Forum Moderators: coopster

Message Too Old, No Replies

Date Function Way, Way off

         

neophyte

7:21 am on Jun 15, 2010 (gmt 0)

10+ Year Member



Hello All -

Am working on some date code this morning and the wierdest thing is happening. When I run the following script (that I've done a million times before on other projects) the date shown is 06-30-10. The time is correct, but the date is 15 days into the future.

ini_set('date.timezone','Asia/Hong_Kong');

echo date('m-t-y / H:i', time());

It's always worked perfectly before.

Anyone have any idea what's causing this?

Neophyte

L33t_J0rdan

7:24 am on Jun 15, 2010 (gmt 0)

10+ Year Member



ini_set('date.timezone','Asia/Hong_Kong', -15);

I don't know if that'll work but it might XD

incrediBILL

7:42 am on Jun 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you checked the actual server time?

Sometimes when a server is rebooted, for reasons unknown, the hardware clock may not match real time (bad lithium batteries?), perhaps the universal time clock synch task is failing to start or can't connect to the universal time clock.

Not always a simple matter.

If you have SSH access and it's a Linux server, just type the command DATE and see what it says.

coopster

1:31 pm on Jun 15, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Anyone have any idea what's causing this?


Yeah, it is the "t" ...

echo date('m-t-y / H:i', time());


t     Number of days in the given month     28 through 31


date [php.net]

Readie

6:23 pm on Jun 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to add to Coop's post -

What you want to be using is "d" -

echo date('m-d-y / H:i');

For the record, if no secondary argument is supplied to date() then time() is assumed.

neophyte

1:05 am on Jun 16, 2010 (gmt 0)

10+ Year Member



Wow, do I feel like a complete moron. Yep, it was suppose to be 'm-d-y'.

Thanks to all (especially Coopster) for revealing the oh-so-obvious error of my ways.

L33t_J0rdan

6:25 am on Jun 16, 2010 (gmt 0)

10+ Year Member



Congrats on fixing!