My timestamp is 8 hours behind my local time so typically
2015-08-24 12:50:07
Can I update this to
2015-08-24 20:50:07
Try to use field of datetime type instead and obtain the value by function NOW()
Related
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.
I have a datetime 0000-00-00 00:00:00 column in my table,
Need to keep the minute and seconds when updating ____-__-__ __:MM:SS
but also change the date and hour to current time.
How can I achieve this on MySQL side?
Edit (Sample):
Current Date field value: 2016-06-27 15:13:07
We Update this table at 2016-07-28 12:31:18
Desired Date field value: 2016-07-28 12:13:07
As you can see the updated date still has correct 2016-07-28 12: but the :13:07 (minutes and seconds) are Selected from the date before update and replaced by current time's minutes and seconds
You can make use of MySQL CONCAT() function. Your update query would looks something like this,
UPDATE table_name
SET
date_column = CONCAT('2016-06-29 15:',MINUTE(date_column),':',SECOND(date_column))
WHERE
column_id = 1
CONCAT() returns the string that results from concatenating the given arguments.
So in your case we would update date and hour by adding first argument as 2016-06-29 15:, and then use the same minute and second from the same column. And concatenate all the arguments to make the new value as you need.
http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat
I need to update a column with datatype as timestamp. I run the following query:
update job_info set ProcessStartTime = UNIX_TIMESTAMP(CURDATE()) where JobID=4;
But it updates with a value : 0000-00-00 00:00:00 What could be the reason for this? Is the query incorrect?
Don't use UNIX_TIMESTAMP because MySQL UNIX_TIMESTAMP() returns a Unix timestamp in seconds or your column type is datetime
update job_info set ProcessStartTime =CURDATE() where JobID=4;
or use NOW()
update job_info set ProcessStartTime =NOW() where JobID=4;
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
I am new developer in .net,I Have requirement..like this ,when user pick date from date picker not time only date he/she pick up,then click insert that time ,i want insert that date and time is into Column exist with name "EnterdDate" data type is "DATETIME". by default 00:00:00 is stored in the Time format I don't want to be stroed that values I want store The at the Time insertion MySql Server Time.
ex:user 12/03/2013 ->insert->click presently assume server time is 13:00:00
i want insert This Date value --> 2013-03-12 13:00:00 ok for me.
after 10 min I want insert the another record at time i want 2013-03-12 13:10:00
like server time in place of default time i am needed
*i don't need the DateAndTime like is :2013-03-12 00:00:00 not Ok for me.
please give best answer the above question.**
Use ADDTIME() to add the CURTIME() to the given date literal:
INSERT INTO my_table
(EnteredDate)
VALUES
(ADDTIME(CAST('2013-03-12' AS DATETIME), CURTIME())
One needs to CAST() the literal to a DATETIME value because ADDTIME() does not work with DATE types.