In PHP, date_default_timezone_set() sets the default timezone used by all date and time functions in your script. It returns true on success and false if the timezone name is not valid.
Once you set the timezone, functions such as date(), mktime() and strtotime(), and any DateTime created without a timezone, use it. The change lasts until the script ends or you change it again. The timezone name must be a valid identifier like Asia/Kolkata, not an abbreviation like IST.
Syntax
Call date_default_timezone_set() with the values you need. Start with this line.
PHP
date_default_timezone_set('Asia/Kolkata');
Call
What it does
date_default_timezone_set('UTC')
Uses Coordinated Universal Time. This is a good default for servers.
date_default_timezone_set('Asia/Kolkata')
Uses Indian Standard Time, which is UTC+05:30.
date_default_timezone_set('America/New_York')
Uses US Eastern time and switches between EST and EDT automatically.
Use region and city identifiers such as Europe/Berlin. They know about daylight saving time. You can list the valid names with timezone_identifiers_list(). An invalid name returns false, and PHP also raises a notice, so check the result in production code.
Required. The timezone identifier, such as UTC, Europe/London or Australia/Sydney. Abbreviations like EST work in some contexts but are not recommended.
Return Value
Return Value
Description
true
The timezone was valid and is now the default.
false
The identifier is not valid. The old default stays active and PHP raises a notice.
PHP Examples
Example 1 — One Moment, Three Timezones
A Unix timestamp is the same everywhere, but date() prints it using the default timezone. Change the timezone to see different clock times.
in_array() checks that the name exists in the list of valid identifiers.
Only a valid name reaches date_default_timezone_set(), and the getter confirms it.
In January Berlin is on CET, one hour ahead of UTC, so noon UTC prints as 13:00.
In July Berlin is on CEST, two hours ahead of UTC, so noon UTC prints as 14:00.
Frequently Asked Questions
It sets the default timezone for all date and time functions in the current script. After calling it, date(), strtotime() and new DateTime() use that timezone.
The function returns false, raises a notice, and keeps the previous timezone. Use a name from timezone_identifiers_list() to avoid this.
Use Asia/Kolkata. Identifiers with a region and city are unambiguous and handle daylight saving rules, while abbreviations can mean different zones.
No. It only lasts for the current script run. To change it for every script, set date.timezone in php.ini.
No. It only affects PHP. Your database connection has its own timezone setting, so set both when you store or compare dates.