Manipulating dates in PHP



So a client asked me 10 minutes ago if I would mark it on my calendar to disable logins for their web site starting on December 7th, 2009. An easy thing to do when you know the fast and fun way of doing it.

Don't get me wrong, there are plenty of ways to manipulate dates (in PHP), but they seem too high maintenance. I didn't want to convert to unix time or worry about the mktime function when I just needed a quick and dirty solution that I could remember without reviewing syntax.

In other words, I wanted a date that I could manipulate fast! What did I do, I turned to strtotime().

<?php if (strtotime("now") >=strtotime("december 7, 2009")) {
$message="Sorry, the deadline for rewards redemption has passed.";
} ?>

So there you go. I like strtotime because you can use natural dates to do comparisons. Just my preference, but sure beats the alternatives in my opinion. Please comment if you have other cheap tricks for manipulating dates, I'm always interested.

Read and post comments | Send to a friend




Comments

Popular posts from this blog

Apple TV - Recover from nothing Take 2

Convert a LiveCycle Form back to an Acrobat Form

Dear Steve