Tomas
Tomas

Reputation: 59505

How to add 2 hours to TIME type in mysql?

How can I add two hours to the mysql field of TIME type? This problem seems unsolvable to me. I have tried:

1)

select TimeStart + interval 2 hour
from table

returns null

2)

select addtime(TimeStart, interval 2 hour)
from table

returns error

3)

select convert_tz(TimeStart, 'GMT', 'CEST')
from table

(because the 2 hour difference was due to messed up timezones, so this is another way to correct it)

also returns null!

4)

select date_add(TimeStart, interval 2 hour)
from table

also returns null!

I start to curse mysql... would be easy with DATETIME type, but really not very easy to work with the TIME type.

Upvotes: 0

Views: 122

Answers (2)

Tomas
Tomas

Reputation: 59505

Sorry I just figured it out!

addtime(TimeStart, '2:00')

Not very intuitive and consistent with the INTERVAL thing though!

Upvotes: 2

Sablefoste
Sablefoste

Reputation: 4192

SELECT HOUR(TimeStart)+2 FROM table

gives you the 2 hour increment.

Upvotes: -1

Related Questions