News 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

PHPro.org: PHP Security

Pierre-Alain Joye's Blog: Howto use a single php.ini for cli/cgi with htscanner, use 0.7.0 or later

Sitecritic.net: Simple Content Management in PHP Without Database Access

IBM developerWorks: Five good programming habits in PHP

Hardened-PHP Project: phpMyAdmin - error.php XSS Vulnerability


Community Events





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


introduction code unittest laravel release podcast threedevsandamaybe list community interview language install opinion framework refactor symfony2 developer series configure testing

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