Hi guys i am using php date function to show date. But there is a problem with date function of php it is showing a date of yesterday. I am in Dubai so the date of today in my country is
2013年02月23日 but php date function showing me date 2013年02月22日 please tell me how to correct it.
I am using this date function of php
date("Y-m-d");
3 Answers 3
You want to set the default time zone to get the right information. Since you said you're in Dubai then you most likely want:
date_default_timezone_set('Asia/Dubai');
Try adding that line to your initialization of the script before the date call and it should be corrected to be for your country.
Reference Manual for PHP on the function and the available time zones:
http://php.net/manual/en/function.date-default-timezone-set.php http://www.php.net/manual/en/timezones.php
Comments
Use date_default_timezone_set to set timezone because server you are using might have different timezone set.
<?php
$timezone = "Asia/Dubai";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
echo date('d-m-Y H:i:s');
?>
Comments
Have you checked date & time settings on your machine? The code below works fine on my machine, shoing current date date("y-m-d");