Convert MySQL UTC datetime to UNIX timestamp

2010-12-29T03:21:39

These both correctly return the current UNIX timestamp:

SELECT UNIX_TIMESTAMP(LOCALTIMESTAMP()); #MySql
echo time(); //PHP

But I'm storing UTC_TIMESTAMPs in my database (not LOCALTIMESTAMPs).

How can I convert a UTC datetime to a UNIX timestamp using MySQL?

Copyright License:
Author:「Emmett」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/4548780/convert-mysql-utc-datetime-to-unix-timestamp

About “Convert MySQL UTC datetime to UNIX timestamp” questions

These both correctly return the current UNIX timestamp: SELECT UNIX_TIMESTAMP(LOCALTIMESTAMP()); #MySql echo time(); //PHP But I'm storing UTC_TIMESTAMPs in my database (not LOCALTIMESTAMPs). Ho...
I'm trying to convert a datetime field, which is set to EST, to a UNIX timestamp. But the catch is, the timestamp should be set to midnight UTC. For example, May 1 2015 would be 1430438400000 ...
There are many similar questions out there but I believe this one is unique. (Sorry if it isn't) Our database has datetime field named "date_sampled", of which we store with UTC_TIMESTAMP() Our g...
I have a Joda DateTime object representing a UTC time, and wish to store it in a Timestamp field in a MySql table. I have the following code: String ztime = "2013-10-07T08:00:00Z"; DateTimeFor...
I'm confused about timezone differences when converting a MySQL datetime to Unix timestamp. It appears to me that MySQL datetimes (2011-02-07 09:45:00) are in the server's local timezone. I want to
I'm struggling with this small snippet: import time from datetime import datetime start = "2022-05-14T10:00:00" start_date = datetime.fromisoformat(start) start_unix = time.mktime(start_...
When I try to convert from UTC timestamp to normal date and add the right timezone I can't find the way to convert the time back to Unix timestamp. What am I doing worng? utc_dt = datetime.
I have date in the as string in the following format: 202001010000 I am trying to convert this to UNIX format and get the result in UTC I did: import datetime stime = "202001010000" pri...
A unix timestamp is an int which gives the number of seconds since January 1, 1970, UTC. Is there a way to convert the .NET timestamp to unix timestamp using python ? or can this only be done in C...
I want to know that how to get utc datetime from unix_timestamp in mysql. But, I should not use CONVERT_TZ. (because Could not use timezone function in partitioning.) The error occurs in the SQL

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.