PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

DZone.com: Date and time in PHP 5

Note: This article was originally published at PHPDeveloper on 2 December 2010.
PHPDeveloper

New on the Web Builder Zone today, there's an article about DateTime in PHP5 from Giorgio Sironi introducing you to this very handy built-in feature.

PHP has made some progress here as well, for example with the Standard Php Library and its interfaces. Though, the SPL is incomplete and oriented to performance more than to object-oriented programming: take a look at the SplStack and SplQueue implementation containing 20 different methods to get the idea. However a little gem is shipped with each PHP installation: the datetime extension, which contains the DateTime class and its siblings. Ideally, everything you can do with date_* functions, you can do it with this class.

He includes some code that shows the DateTime object in action as a part of a PHPUnit test case - adding days, subtracting months, date difference and its support of operator overloading. There's also mention of Doctrine's native support for the extension.