Return to Snippet

Revision: 65530
at December 14, 2013 06:55 by gromitski

Initial Code
function checkDateAndTime($day,$month,$year,$hour,$minute) {
$dateForConverting = $day."-".$month."-".$year."@".$hour.":".$minute;
$formattedDate = date_create_from_format("[email protected]:i", $dateForConverting);
$newDate = date_format($formattedDate, "Y-m-d H:i:s");
$now = date("Y-m-d H:i:s", time());
$newDateInSecs = strtotime($newDate);
$nowInSecs = strtotime($now);
$returnBool = true;
$diffInSecs = $newDateInSecs - $nowInSecs;
if($diffInSecs < 0) { $returnBool = false; } 
return $returnBool; }

Initial URL

Initial Description
Examine a date and return false if it's in the past, or true for the future.

Slightly more complicated than it needs to be, however there's an easy tutorial with full explanation if you follow the attached link.

Initial Title
Check if a date is in the past or the future

Initial Tags
php, date

Initial Language