0

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

1

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

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

Comments

1

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');
?>

list of timezone

Comments

0

Have you checked date & time settings on your machine? The code below works fine on my machine, shoing current date date("y-m-d");

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.