Problem with PHP Timestamp

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
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Problem with PHP Timestamp

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Problem with PHP Timestamp

Post by AbraCadaver »

Daylight Saving Time? This year it ends November 7th, so your code is likely correct.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Problem with PHP Timestamp

Post by agriz »

Hi,

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

Is there a way to fix it?

Regards
Mahesh
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Problem with PHP Timestamp

Post 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');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Problem with PHP Timestamp

Post by agriz »

Amazing and awesome.

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

Regards
Mahesh
Post Reply