News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Brian Moon's Blog:
Errors when adding/subtracing dates using seconds
January 17, 2012 @ 11:19:22

Brian Moon has a reminder about date handling in PHP - days are not always 86400 seconds long, sometimes there's "leap seconds" included too. Thankfully, there's easy ways around it:

The problem with this is that it assume that there are only 86400 seconds in every day. There are in fact not. On days when the clocks change for daylight savings time, there are either 1 hour more than that or 1 hour less than that. In addition, there are also leap seconds put into our time system to keep us in line with the sun. There is one this year, 2012, on June 30th in fact. Since they don't happen with the regularity that daylight savings time does, it may be easy to forget those. Luckily, for this problem, the solution is the same.

His first solution involves letting strtotime do the work for him, internally calculating the leap seconds or any other issue that might come up. As an alternate solution, he also mentions "doing your math at noon" - this gives you enough leeway to make the offset leap seconds could cause a much smaller risk.

0 comments voice your opinion now!
error add subtract date seconds strtotime noon


blog comments powered by Disqus

Similar Posts

International PHP Magazine: Poll Question: Features a PHP Editor Should Possess

PHPBuilder.com: An introduction to PEAR's Validate package

Debuggable Blog: Supressing Errors in PHP

Hasin Hayder's Blog: Vulnerable bug in CodeIgniter which took us hours to fix our corrupted database

Brian Moon's Blog: Errors when adding/subtracing dates using seconds


Community Events











Don't see your event here?
Let us know!


hhvm language composer package component security unittest example hack application opinion release code introduction overview podcast facebook install framework symfony2

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework