PHP – Parse string into date and date comparison

// Get the date in string with Y-m-d format
$exp_date_s = "2013-04-22";
$today_s = date("Y-m-d");

// Convert the dates into timestamp
$exp_date = strtotime($exp_date_s);
$today = strtotime($today_s);

// Compare the timestamp
if ($exp_date > $today) {
  // Not yet expired
} else {
  // Expired
}

Done =)

Reference: Comparing Dates in PHP

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.