Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0000-00-00 00:00:00 entered as MySQL DateTime

Tags:

mysql

Below is the CREATE TABLE statement used to create my table:

CREATE TABLE IF NOT EXISTS `data_received` (
 `id` int(10) unsigned NOT NULL,
 `edit_time` datetime NOT NULL}

Below is how data is saved in table if 'edit_time' value is not provided:

id  edit_time
1   0000-00-00 00:00:00

Now, if I execute the following statement:

SELECT TIMESTAMPDIFF( HOUR , edit_time, NOW( ) ) AS diff_in_hours
FROM data_received;

I get result: NULL

Can someone please help me understand what is happening?

like image 487
Shahriar N Khondokar Avatar asked Oct 16 '12 12:10

Shahriar N Khondokar


1 Answers

That is because 0000-00-00 00:00:00 is not a valid DATETIME expression accepted by the function.

Please check documentation.

like image 113
hjpotter92 Avatar answered Oct 17 '22 11:10

hjpotter92