News Feed
Sections




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

Slawek Lukasiewicz's Blog:
Working with date and time in object oriented way
June 10, 2011 @ 08:13:14

Slawek Lukasiewicz has a new post today about working with dates and times in PHP on a more object-oriented fashion than in the more traditionally procedural way of just calling PHP date/time functions on the string values.

Date and time manipulation in PHP is mostly connected with functions like: date, time or strtotime. They can be sufficient, but if we want to deal with dates like with objects - we can use DateTime class. DateTime class is not only straightforward wrapper for standard functions, it has a lot of additional features - for example timezones.

He shows how to use the DateTime functionality to return an object you can call several different methods on. He gives examples of the formatting call, comparing one DateTime object to another, how to update the date after the object's created, calculating the difference between two dates and iterating through a certain time period.

1 comment voice your opinion now!
time date datetime objectoriented procedural tutorial


blog comments powered by Disqus

Similar Posts

Alexander Netkachev's Blog: A little bit more about Zend_Controller plugins

Matthew Weier O'Phinney's Blog: Rendering Zend_Form decorators individually

Till Klampaeckel's Blog: Cooking PHPUnit (and a chef-solo example on top)

Developer.com: Sending Email with PHP

DevShed: Filtering Image Streams with the GD Library in PHP


Community Events

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


security threedevsandamaybe release series symfony api laravel5 podcast language unittest library laravel version extension community opinion framework interview voicesoftheelephpant introduction

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