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

Lorna Mitchell's Blog: Dealing with MySQL Gone Away in Zend Framework

FinalConcept.com.au: Symfony: Unbound sfForm: Unexpected extra form field named

Nexen.net: Error Messages in PHP (a Search)

Maggie Nelson's Blog: Beyond Error Logs

Sameer Borate's Blog: Top 25 Most Dangerous Programming Errors


Community Events

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


interview voicesoftheelephpant library video extension laravel5 community development psr7 conference podcast laravel framework language release api opinion introduction series unittest

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