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

PHPEverywhere: PDO beta revisited

Enavu.com: PHP Smart Date Parsing: Natural Language Input (task.fm explained)

Stefan Mischook's Blog: Turning on display_errors in WAMP - Video Tutorial

Jamie Wong's Blog: Effective bugfixing techniques for PHP

Lorna Mitchell's Blog: SugarCRM Installation Error


Community Events





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


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

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