Click here to Skip to main content
15,886,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am trying to enter the following default value and I get as return error code: the default timestamp is not valid.

`registered_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'


What I have tried:

I have then changed to
'2013-06-23 05:09:12'
which is an old date time and this works. This could tell me the user is not registered yet.

But it would be nice to get it cleaner with the
'0000-00-00 00:00:00'
af tried above.

I have found this command:
mysql> SELECT @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


where I think these two keywords:
NO_ZERO_IN_DATE,NO_ZERO_DATE
are the issue.

Is there a way to get rid of it ? or do I have to use a different approach ?

Does somebody have an idea ?
Thanks.
Posted
Updated 30-Sep-19 0:25am

1 solution

Please have a look at MySQL TIMESTAMP[^]:
The TIMESTAMP value has a range from '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
Therefore, '0000-00-00 00:00:00' falls outside this allowed range.

As further note, there is a page which explains the date/time formats you can use in MySQL:
11.3.1 The DATE, DATETIME, and TIMESTAMP Types[^]
 
Share this answer
 
v2
Comments
Maciej Los 30-Sep-19 6:38am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900