Page 1 of 1

Problem with PHP Timestamp

Posted: Wed Jun 02, 2010 3:29 pm
by agriz
Hi,

I am creating a countdown timer.
http://www.agrizlive.com/countdown/index.php

If you select "Countdown End Date" to 1st november, It works fine. But if i select 1st december, then it shows one extra hour.

also, my strtotime function returns the following timestamp for New Year.

$d = "2011-01-01 0:0:0";
echo strtotime($d); //1293861600

In that counter i gave 2010-01-01 00:00:00 // Works fine.
In that counter i gave 2011-01-01 00:00:00 // There is a problem.

Please give me advice on this.

Regards
Mahesh

Re: Problem with PHP Timestamp

Posted: Wed Jun 02, 2010 3:50 pm
by AbraCadaver
Daylight Saving Time? This year it ends November 7th, so your code is likely correct.

Re: Problem with PHP Timestamp

Posted: Thu Jun 03, 2010 1:58 am
by agriz
Hi,

Thanks for the information.
Yes. It is daylight saving.

Is there a way to fix it?

Regards
Mahesh

Re: Problem with PHP Timestamp

Posted: Thu Jun 03, 2010 9:05 am
by AbraCadaver
agriz wrote:Hi,

Thanks for the information.
Yes. It is daylight saving.

Is there a way to fix it?

Regards
Mahesh
I don't know how you are doing your calculations, but you can probably calculate it in a timezone that doesn't observe daylight saving time like GMT/UTC:

Code: Select all

$diff = strtotime($future . ' UTC') - strtotime($now . ' UTC');

Re: Problem with PHP Timestamp

Posted: Fri Jun 04, 2010 8:10 am
by agriz
Amazing and awesome.

Short and sweet solution. Adding utc fixed the problem.
Thanks for your help

Regards
Mahesh