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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s