Hi,
I want to know that how can I get the timestampdiff return as zero instead of null. For example I have a query in which both dates are exactly same but the query returns me null instead of 0. My query is

SELECT (TIMESTAMPDIFF(HOUR,'2012-12-01 11:15:00','2012-12-01 11:15:00'))

And this code is returning me null instead of zero. How can I fix this problem.
Thanks in advance.

SELECT IFNULL(TIMESTAMPDIFF(HOUR, '2012-12-01 11:15:00', '2012-12-01 11:15:00'), 0)

i am not sure why are you getting null because i tried in my system and it is giving zero.

As from http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampdiff

Returns datetime_expr2 – datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. One expression may be a date and the other a datetime; a date value is treated as a datetime having the time part '00:00:00' where necessary. The unit for the result (an integer) is given by the unit argument. The legal values for unit are the same as those listed in the description of the TIMESTAMPADD() function.

8241b8567a7ba5c2f213b33c15a56b37

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.