Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save records in MYSQL db with CURRENT_TIMESTAMP in UTC format and NOT LOCALTIME?

Save records with column as 'created_date' which has CURRENT_TIMESTAMP which should be UTC time and not local time

like image 243
Pranoti Buradkar Kokas Avatar asked Dec 22 '25 10:12

Pranoti Buradkar Kokas


1 Answers

UTC_TIMESTAMP() function

In MySQL, the UTC_TIMESTAMP returns the current UTC date and time as a value in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuuuu format depending on the usage of the function i.e. in a string or numeric context.

Note : Since UTC_TIMESTAMP() works on current datetime, your output may vary from the output shown.

Syntax: UTC_TIMESTAMP; UTC_TIMESTAMP()

Code: SELECT UTC_TIMESTAMP,UTC_TIMESTAMP();

Sample Output:

 mysql> SELECT UTC_TIMESTAMP,UTC_TIMESTAMP();
+---------------------+---------------------+
| UTC_TIMESTAMP       | UTC_TIMESTAMP()     |
+---------------------+---------------------+
| 2015-04-14 22:52:11 | 2015-04-14 22:52:11 | 
+---------------------+---------------------+
1 row in set (0.01 sec)

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!