News Feed
Sections




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

Derick Rethans' Blog:
Storing Date/Times in Databases
March 30, 2010 @ 09:16:14

Derick Rethans has a new post to his blog that helps to demystify some of the confusion around storing dates correctly in your application's database. He mentions a suggested method of using the UTC time and offset together, but talks about why this isn't the best alternative.

After my talk during ConFoo on Advanced Date/Time Handling I received a question about whether the UTC-offset, together with the date/time in years, months, days, hours, minutes and seconds, was enough for storing a date/time in a database and still being able to do calculations with this. The answer to this question was no, but it lead to an even more interesting discussion about what would be enough to store an accurate date/time in a database.

He mentions the main issue with the UTC-offset method - time changes like Daylight Saving throwing a wrench into the works and how adding/subtracting hours doesn't always work as expected. His suggestion is to store the actual DateTime object information representing the location in question, the timezone identifier and the date/time information as strings. Then, when you need to calculate the date information on the other side, you can recreate it with a DateTime and DateTimeZone objects.

0 comments voice your opinion now!
datetime database tutorial utc offset


blog comments powered by Disqus

Similar Posts

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 12)

PHPMaster.com: Rapid Application Development with CakePHP

HowTo Forge: Installing The PHP-MSSQL Module On CentOS 5.0

Qandidate.com Blog: Using the Accept Header to version your API

Sameer Borate: Simple user authentication in Laravel 4


Community Events

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


language voicesoftheelephpant community symfony2 laravel release framework example series introduction application podcast performance opinion interview php7 configure conference part2 api

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