Jump to content

Date Comparison


kevinfwb

Recommended Posts

Convert the dates to UNIX timestamps, put them into an array, sort them, compare each one in ascending order with today's UNIX timestamp. The first one that is greater than or equal to today's timestamp is the one you want:

<?php
$dates = array(strtotime($date1),strtotime($date2),strtotime($date3),strtotime($date4),strtotime($date5));
sort($dates);
$now = time(); // Today's timestamp
$foundit = false;
for($i=0;$i<count($dates);$i++) {
    if ($dates[$i] >= $now && !$foundit) {
       $target = $dates[$i];
       $foundit = true; }
}
echo 'The next date is ' . date('l , F jS, Y',$target);
?>

 

Note: untested.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/42785-date-comparison/#findComment-207688
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.