cancel
Showing results for 
Search instead for 
Did you mean: 

How to add hours to time filed

Former Member
0 Kudos

Hi,

In one of my project we have requirement to check the time field column<= time field column+ 2 hrs,here my problem is without converting timefield column into datatime filed i couldn't add the 2 hrs time. is there any function in hana to add directly time into timefiled column.

Regards,

Harish

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182302
Active Contributor
0 Kudos

Did you try ADD_SECONDS?

Regards,

Krishna Tangudu

Former Member
0 Kudos

Hi Krishna,

For ADD_SECONDS we need datatime object but i have only time field in my DB.

Regards,

Harish

Former Member
0 Kudos

Hi. You may use anywhere:

select to_time(now()),to_time(add_seconds(to_time(now()),7200)) from dummy

Former Member
0 Kudos

Hi Dmirity,

Thanks for your reply.

I have column name ENDTIME and sample data is 04:30:15 PM, can i add 2 hrs for the end time column?

Regards,

Harish

lbreddemann
Active Contributor
0 Kudos

Just follow the advice you already got.

If your data is stored as time, maybe as a string, you need to convert it to a time data type before:

select add_seconds(to_time ( '04:30:15 PM'), 60*60*2) from dummy;

so for your case

select add_seconds(to_time ( ENDTIME), 60*60*2) from <table name>;

Former Member
0 Kudos

Shure you can!

Just try one of this examples:

1) select to_nvarchar(to_time(add_seconds(to_timestamp(endtime,'HH12:MI:SS PM'),7200)),'HH12:MI:SS AM') from

(select '04:30:15 PM' as endtime from dummy)

2) select to_time(add_seconds(endtime,7200)) from

(select '04:30:15 PM' as endtime from dummy)

The first is format example, and the second is default formatting.

to_nvarchar function is for clear understanding;)

Former Member
0 Kudos

Hi Lars,

I have already tried the solution what you suggested. When i add 1 hr to the time field it will works but when i try for 2 hrs it will give following error

numeric overflow: search table error:  [6944] AttributeEngine: overflow in numeric calculation;secondtime [here]add_seconds(secondtime "ENDTIME", int '7200'),ENDTIME = 23:45:00[secondtime]

Regards,

Harish

Former Member
0 Kudos

If You need it in AT_VIEW - try to use

addseconds(secondtime("ENDTIME"),7200)