Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect datetime value for future date in mysql

Tags:

mysql

MySQL statement:

insert into `banners` 
    (`path`, `app_id`, `enabled`, `from_date`, `to_date`, `updated_at`, `created_at`) 
values 
    ('banners/example.png', 'com.example.ccp_attacker', 1, '2000-01-01 00:00:00', '2099-12-31 00:00:00', '2100-06-04 00:00:00', '2100-06-04 00:00:00')

generates error #1292 - Incorrect datetime value: '2100-06-04 00:00:00' for column 'updated_at' at row 1

Why 2100-06-04 00:00:00 is not a valid time?

like image 867
Michael Tsang Avatar asked Dec 02 '16 03:12

Michael Tsang


People also ask

How do I fix incorrect datetime value in MySQL?

With the STR_TO_DATE() function, the previous INSERT statement won't cause an error: INSERT INTO example (last_update) values(STR_TO_DATE("10-17-2021 15:40:10", "%m-%d-%Y %H:%i:%s")); And that's how you can fix the error Incorrect datetime value in MySQL.

How to solve error 1292 in MySQL?

You just need to go to the Wamp panel, then to MySQL, then to settings and change the mode to sql-mode: none. (essentially disabling the strict mode) The following picture illustrates this.

How do I insert date in YYYY-MM-DD format in MySQL?

Introduction to MySQL DATE data type This format is fixed and it is not possible to change it. For example, you may prefer to use mm-dd-yyyy format but you can't. Instead, you follow the standard date format and use the DATE_FORMAT function to format the date the way you want. MySQL uses 3 bytes to store a DATE value.

What is MySQL datetime format?

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.


1 Answers

MySQL date does not excees 2038. This is a very old problem and for some reason they are not solving it. The max value for acceptable date in MySQL is 2038. When I faced this issue I saved the date in MySQL as varchar and later converted it to date in the business logic.

like image 135
omar jayed Avatar answered Oct 30 '22 08:10

omar jayed