Quantcast
Channel: Eureka! » PHP
Viewing all articles
Browse latest Browse all 16

PHP – Parse string into date and date comparison

$
0
0
// 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


Filed under: PHP Tagged: PHP

Viewing all articles
Browse latest Browse all 16

Trending Articles