views:

241

answers:

3

I have two columns: beginTime and duration. I'm trying to calculate the endTime. The problem is that i get empty results back.

I have tried several things.

DATE_ADD(startTime, INTERVAL `duration` MINUTE) AS endTime

DATE_ADD(startTime, INTERVAL '10' MINUTE) AS endTime

DATE_ADD(startTime, INTERVAL 10 MINUTE) AS endTime

But everytime the result is empty. startTime is not empty. It is a time field in the format 09:00:00.

Can anyone help me with this?

A: 

This works for me:

SELECT DATE_ADD(`startTime`, INTERVAL 10 MINUTE) AS endTime FROM `users` WHERE 1
bjelli
What is the field-type of `startTime`?
Ikke
A: 

In DATE_ADD first parameter supposed to be Date field not Time field. Can you try changing the start time to Date format ('0000-00-00 00:00:00') and try?

Umesh
+1  A: 

DATE_ADD will return NULL if the time format is incorrect, along with a warning:

mysql> \W
Show warnings enabled.
mysql> SELECT DATE_ADD('25:00:00', INTERVAL 10 MINUTE) AS endTime
    -> ;
+---------+
| endTime |
+---------+
| NULL    |
+---------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1292): Incorrect datetime value: '25:00:00'

Also note that 'hh:mm:ss' is not a correct datetime format. You need to have year, month and day also.

Could you please enable warnings in MySQL and repeat the query with your data?

Quassnoi
This is the message I get when I exequte my query: Warning (Code 1264): Out of range value for column 'startTime' at row 1. Probably because of the wrong type. How can i add minutes to a time field?
Ikke