date() help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lpangm03
Forum Newbie
Posts: 5
Joined: Mon Mar 17, 2008 10:06 am

date() help

Post 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?
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Re: date() help

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: date() help

Post by RobertGonzalez »

Time comes from your computers system time.

It also help if you have the date.default_timezone php.ini setting set.
lpangm03
Forum Newbie
Posts: 5
Joined: Mon Mar 17, 2008 10:06 am

Re: date() help

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: date() help

Post 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.
lpangm03
Forum Newbie
Posts: 5
Joined: Mon Mar 17, 2008 10:06 am

Re: date() help

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: date() help

Post by RobertGonzalez »

What time is it on the computer that you are running that code on?
lpangm03
Forum Newbie
Posts: 5
Joined: Mon Mar 17, 2008 10:06 am

Re: date() help

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: date() help

Post by RobertGonzalez »

And you restarted your web server after you changed php.ini right?
lpangm03
Forum Newbie
Posts: 5
Joined: Mon Mar 17, 2008 10:06 am

Re: date() help

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: date() help

Post 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.
Post Reply