3

I know that using this query I can set time per session in mysql server

SET SESSION time_zone = '+04:00'

Question is how to detect this +04:00 (it can vary during year because of daylight saving time) part in PHP for my country?

enter image description here

3 Answers 3

4

Try using the timezone name (like America/Chicago) instead of +/- a set of hours. This should take into account daylight savings time.

You will need to load zoneinfo into your mysql database if you haven't already.

Sign up to request clarification or add additional context in comments.

3 Comments

how to load zoneinfo? The problem is will this zoneinfo work in shared hosting servers?
It may already be installed. If you can set session with the timezone name then you should be good to go. You would need admin access to load zoneinfo into mysql.
See this link: dev.mysql.com/doc/refman/5.6/en/mysql-tzinfo-to-sql.html for description how to load timezone database into MySql.
1

I will take a guess that perhaps you are in Azerbaijan? If so, you should use the IANA time zone id of Asia/Baku. This time zone alternates between a standard offset of +4:00 and a daylight offset of +5:00.

See "Time Zone != Offset" and "Time Zone Databases" in the timezone tag wiki.

If you need to do this in MySQL, you will need to load the IANA time zone database (aka "zoneinfo") into MySQL using mysql_tzinfo_to_sql. Thanks to datasage and kordirko for this tip.

But often the better approach is to only store UTC times in your database. You can do timezone translations directly in PHP using the DateTime and DateTimeZone classes. PHP also implements the same IANA time zone database, and you can find Asia/Baku on PHP's list of supported time zones.

Comments

0

Open your my.ini file. For windows it is in /mysql/bin/my.ini Search for the section mysqld. in this section enter -

default-time-zone = '+00:00'

+00:00 is the offset from GMT. Check out the time-zone-support page for better reference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.