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");
Dipesh Parmar
27.3k8 gold badges65 silver badges92 bronze badges
asked Feb 23, 2013 at 5:56

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

answered Feb 23, 2013 at 6:00
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

answered Feb 23, 2013 at 6:00

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");

answered Feb 23, 2013 at 6:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.