MySQL: Timezone issue with unix_timestamp()

This MySQL query:
SELECT unix_timestamp('2015-10-01 00:00:00')

Open in new window

1443672000 which is at 4:00 am
however I want it to return
1443657600 which is at midnight.

The problem is likely caused by a timezone issue, where a Unix Timestamp should always be in UTC time however MySQL is doing the calculation based on the time zone of the server.
LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add the timezone to the string
Unix_timestamp('2015-10-01 00:00:00 -0400')

Or use the TIMezone in the query, GMT/UTC is presumed if absent.
See also the conver_tz option that includes the timezone .......
Ref the date/time command from prior
skijAuthor Commented:
Thank you but I am still confused.  Your first idea of adding the timezone offset to the string by hardcoding  -0400 is not an option for me because this needs to work reliably on any server independently of the timezone offset.  I don't want to have to convert the timezone or specify the timezone for the same reason.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Given that restriction, you have to then take into account that unix_timestamp presumes GMT/UTC while the output converting the unix timestamp then should use a non local time converter.

Please the date/time function to deal with timezone handling.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
Here is the man page   Here is info on setting the time zone   Note that you probably have to be 'root' to do that since it appears that it sets it for the entire server.
skijAuthor Commented:
Thanks.  I will use this:
SELECT UNIX_TIMESTAMP(CONVERT_TZ('2015-10-01 00:00:00', '+00:00', @@global.time_zone))

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.