Page 1 of 1

date() help

Posted: Mon Mar 17, 2008 10:12 am
by lpangm03
Hi,

I'm using WAMP on my home computer for my PHP scripts, during my learning process.

I have a piece of code that is to get the date in this format: 20080316 (that would be today's for example). This is what I'm using: date('Ymd').

Now, my question is, where is it pulling the date from? Because for some reason, everytime the clock hits 11PM, it displays this date: 20080317, as if today is actually tomorrow. So basicly, the PHP script is 1 hour ahead of my computer's clock.

Any tips on how I can fix this?

Re: date() help

Posted: Mon Mar 17, 2008 3:14 pm
by SpecialK
Although I don't know where it's pulled from, it may be an issue with the changes of "Spring Forward" being off an hour for those extra three weeks for that North America change. Obviously it's not acceptable because it will 'correct itself' once that date changes, but will happen in both the spring and fall.

Interesting bug as I've never used windows with PHP so maybe windows is using the patch to correct the time but the actual bios time is still 1 hour off?

Re: date() help

Posted: Mon Mar 17, 2008 3:55 pm
by RobertGonzalez
Time comes from your computers system time.

It also help if you have the date.default_timezone php.ini setting set.

Re: date() help

Posted: Mon Mar 17, 2008 7:32 pm
by lpangm03
Everah wrote:Time comes from your computers system time.

It also help if you have the date.default_timezone php.ini setting set.

Thanks a lot. Last question, where could I find my php.ini? Like I said in my earlier post, I'm new to php, and just using this as a learning experience.

Edit: I found my php.ini, and right now, I have this as far as the date is concerned:

Code: Select all

[Date]
; Defines the default timezone used by the date functions
;date.timezone =
 
;date.default_latitude = 31.7667
;date.default_longitude = 35.2333
 
;date.sunrise_zenith = 90.583333
;date.sunset_zenith = 90.583333
Would I be changing that to this:(?)

Code: Select all

[Date]
; Defines the default timezone used by the date functions
;date.timezone =
;date.default_timezone
 
;date.default_latitude = 31.7667
;date.default_longitude = 35.2333
 
;date.sunrise_zenith = 90.583333
;date.sunset_zenith = 90.583333

Re: date() help

Posted: Mon Mar 17, 2008 9:43 pm
by RobertGonzalez
Nope, uncomment the date.timezone line and add to it the location you are from that maps to one of the known PHP timezones.

Remember to restart your web server after the change is made.

Re: date() help

Posted: Mon Mar 17, 2008 11:07 pm
by lpangm03
I apologize if this may be disturbing you, but I'm not exactly sure what you mean by that. Will it look like this:(?) I am in the Detroit time zone.

Code: Select all

[Date]
; Defines the default timezone used by the date functions
date.timezone = America/Detroit
 
;date.default_latitude = 31.7667
;date.default_longitude = 35.2333
 
;date.sunrise_zenith = 90.583333
;date.sunset_zenith = 90.583333
When I try that, and I use the code:

Code: Select all

echo date("F j, Y, g:i a");
to see if it's accurate, and its still 1 hour ahead of what it should be.

Re: date() help

Posted: Mon Mar 17, 2008 11:21 pm
by RobertGonzalez
What time is it on the computer that you are running that code on?

Re: date() help

Posted: Mon Mar 17, 2008 11:28 pm
by lpangm03
Right now, the computer clock is 12:25AM (which is my correct time)
When I run that php code, it comes up as 1:25AM

Re: date() help

Posted: Mon Mar 17, 2008 11:39 pm
by RobertGonzalez
And you restarted your web server after you changed php.ini right?

Re: date() help

Posted: Mon Mar 17, 2008 11:46 pm
by lpangm03
By web server I assume you mean WAMP, the software I use. I restarted that yes. If you mean the entire PC, then no.

Re: date() help

Posted: Mon Mar 17, 2008 11:57 pm
by RobertGonzalez
No, I mean telling apache to turn off then turn on again.

If you are using wamp then I have no idea what could be happening. Generally speaking the web server takes its time from the host machine. But if your time shows as what it really is and the web server sees it an hour ahead, I can only guess that there is a possible daylight saving bug somewhere in the server.

I have never been a big fan of packages apps like that and I have no idea how to move around in them. Sorry.