tags:

views:

131

answers:

5

As i said before, its 20 min past midnight, and when i do check the date using php

as date("Y-m-d"); and date("Y-m-d",strtotime("now"));

i still get the previous days' date. I expected a lot of things to go wrong while coding but definitely not this. I wouldnt even have it in the list of potential-things-that-could-go-wrong. I have refereshed the browser, using SHift + refresh and have also gone to the extent of restarting the system.

What went wrong?

+1  A: 

Is the timezone on the server set properly? How about the timezone for PHP?

Thomas Owens
I am using php at my home computer, with apache. Is setting the time zone necessary?
Yes, it must be set in php.ini or with date_default_timezone_set(), as otherwise PHP must guess and emits a notice.
carl
+4  A: 

Are you sure the server runs on the same time zone as you're expecting?

Try printing out the actual time as well and see if that tells you anything.

Michael Madsen
+1  A: 

Are you sure that you get the correct time? I.e. print more info:

echo date("c")

This will give you everything, date, time, time zone etc.

You can set the timezone you want to use with date_default_timezone_set. You can find a list of valid timezones here.

You can also set a timezone in your php.ini config by setting the date.timezone-directive.

PatrikAkerstrand
2009-09-07T19:07:38+00:00 this is what i get. T
if i use date(strtotime) i get 4230Mon, 07 Sep 2009 19:08:42 +0000302009300809UTC
Looks like it is running GMT time
Lizard
oops i added my own answer before i refreshed the page... thanks machine
A: 

The date doesn't change on subsequent refreshes, or the date didn't change on midnight (from 2009-09-06 to 2009-09-07)?

David Thomas
It changes on refresh
A: 

yup all you folks are right.. it was a problem with the timezone. changed it by adding uncommenting the ;date.timezone property in php.ini and adding the required timezone as given in http://www.php.net/manual/en/timezones.php. Thanks guys