0 votes
in Programming by
retagged by

I am using date function in PHP and storing time into database

Somehow its inserting US time zone and I want india time zone.

Using data function like this :

$today=date('Y-m-d h:i:s');

Please help me!

You can also use .htaccess file (at the root of your project) in which you will set the timezone as follow:
date.timezone = "Europe/Paris"
You must be consistent across your code. Keep in mind you can have at least three different settings: the ini_set in php which affects date() functions, the MySQL setting which affects "SELECT NOW()" and the third one, the server time, which will have an impact on every other thing that is running on your server, and I mean external logs and cgi execs. Best practice: keep everything UTC and use a powerful date library such as Carbon (in php) and moment.js in JavaScript. You cans easily find them both on GitHub.

1 Answer

+2 votes
by (1.4k points)
edited by
Best answer
String date_default_timezone_get ( void )

In order of preference, this function returns the default timezone by:

  • Reading the timezone set using the date_default_timezone_set() function (if any)

  • Prior to PHP 5.4.0 only: Reading the TZ environment variable (if non empty)

  • Reading the value of the date.timezone ini option (if set)

  • Prior to PHP 5.4.0 only: Querying the host operating system (if supported and allowed by the OS). This uses an algorithm that has to guess the timezone. This is by no means going to work correctly for every situation. A warning is shown when this stage is reached. Do not rely on it to be guessed correctly, and set date.timezoneto the correct timezone instead.

If none of the above succeed, date_default_timezone_get() will return a default timezone of UTC.

Date function in PHP returns formatted date string ,

For India time zone you have to set



$today = date('Y-m-d h:i:s a');

Now you would get date with India time zone. 

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated