What's wrong with '2018-03-22 00:00:00" in MySQL? - mysql

I want to update a date field and set it to 2018-03-22 00:00:00 but I get the following stupid error:
Error Code: 1292. Incorrect datetime value: '2018-03-22 00:00:00' for column 'Date' at row 158917
This is the query I use for updating:
update assets.transactions
set date = date_add(date, interval 1 hour)
where date between '2018-03-21 23:00:00' and '2018-06-29 23:59:59';
What is wrong? I searched a lot and found out dates before 1970-01-01 00:00:01 are not supported by MySQL, that is acceptable, but a date in the middle of 2018? That's something I can't digest.
Is there any solution to make this work right?

I guess you're updating a TIMESTAMP column. I also guess you have your MySQL instance set to a timezone with a daylight time switchover on 23-March-2018. I guess the rules of your timezone switchover in your country mean that the clock rolls over from 21-March-2018 11:59:59 to 22-March-2018 01:00:00.
So the value 2018-03-22 00:00:00 just doesn't exist.
Strange, isn't it?
Try issuing this MySQL command, to set the time zone to UTC, before doing these sorts of mass timestamp updates.
SET time_zone = 'UTC';
Don't forget to switch it back before doing other operations. Or just do those operations from a different MySQL connection.

Related

What is the minimum date time value that can be entered in MySQL column of timestamp datatype?

I'm trying to insert a date time value e.g. 1970-01-01 00:00:01 in a column of timestamp datatype in MySQL table but getting following error:
#1292 - Incorrect datetime value: '1970-01-01 00:00:01' for column 'order_date' at row 1
But according to MySQL docs - The TIMESTAMP value has a range from '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
So if the range value starts from 1970-01-01 00:00:01 UTC then why this value can't be inserted in the table? Is there something to do with UTC? What will be the minimum date time value for timestamp that can be inserted without any issue?
Timestamp columns store a utc value and start at 1970-01-01 00:00:01, but whenever you read or write them, they convert to/from your session timezone. This makes them something of a nightmare to work with if you are actually intending to only use UTC.
Just use a datetime type if you ever are trying to set particular times that come from your client. If you must use timestamp and want to set a particular UTC time, first do:
set session time_zone='+00:00';
But note that any client that doesn't do that may see a different time. Even if you set your server timezone to UTC, so that sessions default to UTC, some client libraries "helpfully" set the session timezone when they connect.

Getting Different timestamp when Converting same Unix time in Two Different DB [duplicate]

Unix time stamp conversion giving tow different result in mysql and oracle
select FROM_UNIXTIME(1387444958) from dual;
Output :2013-12-19 10:22:38
select to_char(to_date('01/01/1970 00:00:00','DD/MM/YYYY HH24:MI:SS')+ (1387444958/86400),'YYYY-MM-DD HH24:MI:SS')from dual;
output: 2013-12-19 09:22:38
Can anyone please help me in getting same timestamp from oracle as I am getting in MySql.
Unix timestamp is seconds from 1970-01-01 00:00:00 UTC which is actually 1970-01-01 01:00:00 in your local timezone (or the timezone where your MySQL server is located). Looks like FROM_UNIXTIME takes this into account.
For Oracle you can use this function:
FUNCTION UnixTime2Timestamp(UnixTime IN NUMBER) RETURN TIMESTAMP IS
BEGIN
RETURN (TIMESTAMP '1970-01-01 00:00:00 UTC' + UnixTime * INTERVAL '1' SECOND) AT LOCAL;
END UnixTime2Timestamp;
I assume if you like to get UTC time in MySQL then you have to run
select
CONVERT_TZ(FROM_UNIXTIME(1387444958),'{your local timezone}','UTC')
from dual;

MySQL TIMESTAMP stoped working on summer time transition

I have a stored procedure that was crashing yesterday. It begins like this:
DECLARE v_today TIMESTAMP;
SET v_today = (DATE(NOW()) + INTERVAL 0 SECOND);
I've fixed it changing the type of v_today to DATETIME. But I want to understand why it was generating an error only yesterday (when Brazil started summer time).
The error was:
Mysql2::Error: Incorrect datetime value: '2017-10-15 00:00:00' for column 'v_today' at row 1:
Thanks.
I bet this is a bug in MySQL. Here's the time transition discipline for Brazil. timeanddate.com/time/change/brazil/brasilia It looks like the TIMESTAMP value 2017-10-15 00:00:00 doesn't exist, and needs to be pushed forward an hour to 2017-10-15 01:00:00. But MySQL just gacks.

MySQL - NOW() different value if its in trigger or in select

I have an issue with MySQL NOW() function
if i run:
SELECT NOW();
i get the value:
2015-11-24 13:35:00 (correct value with Swedish winter-time)
But if i use NOW() in a trigger function to update a timestamp column when another column changes like this:
SET NEW.timestamp = NOW();
i get the value:
2015-11-24 12:35:00
How can i solve this or why is it behaving like this?
To get current date and time using NOW(), please set the timezone as per your country to get the correct date and time.
Please check the link here
If you want to change the MySQL server’s time zone to adjust the current date and time returned by the NOW() function, you use the following statement:
SET time_zone = your_time_zone;
MySQL has multiple ways of specifying a timezone - the server has a default time zone and each client can also specify their own time zone on a per-connection basis.
I think that your SELECT is using the time zone specified by your client connection, while the trigger is using the server's default time zone.
https://dev.mysql.com/doc/refman/5.6/en/time-zone-support.html

MySQL updating and converting timezone

I have a database containing times (ex: 2013-07-10 23:25:36)
They're all in Mountain Standard Time (Calgary) and I need to convert them to UTC.
I've tried to use the following statement to do so, and it resets them all to
0000-00-00 00:00:00
UPDATE assets_time SET time=convert_tz(time, 'MST', 'UTC')
I would appreciate any advice, thanks
According to this article:
The value can be given as a named time zone, such as 'Europe/Helsinki', 'US/Eastern', or 'MET'. Named time zones can be used only if the time zone information tables in the mysql database have been created and populated.
So this might be your problem. Also have you tried imputing numbers instead? Like this for example:
mysql>UPDATE assets_time SET time=CONVERT_TZ(time,'-07:00','+00:00');
You must use the standardize format:
UPDATE assets_time SET time=convert_tz(time, 'US/Mountain', 'UTC')
SELECT DATE_ADD(NOW(), INTERVAL -7 HOUR);
General syntax
SELECT DATE_ADD(NOW(), INTERVAL HOUR);
http://www.worldtimebuddy.com/utc-to-pst-converter
since you need for MST it is "-7"