DateTime: My new best friend

Jul 17, 2012 php
This post is more than 18 months old. Since technology changes too rapidly, this content may be out of date (but that's not always the case). Please remember to verify any technical or programming information with the current release.

I have a new love affair… PHP’s DateTime object. I’m not sure when it started, but it’s going on strong now. If you haven’t taken a look at it, I invite you to run over there now and just look at the methods. If that isn’t enough, let me give you a bit of example code… see if this makes you really want to do it:

$firstDate = new DateTime('01/12/2012 10:00:00');
$secondDate = new DateTime('2012-01-01 23:23:23');
echo $firstDate > $secondDate ? "First Date is Newer" : "Second date is newer";

What do you think the output will be? How EASY is that?!

Go to All Posts