note 30976 deleted from function.mktime by sniper

From: Date: Tue, 04 Nov 2003 13:10:48 +0000
Subject: note 30976 deleted from function.mktime by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59874@lists.php.net to get a copy of this message
Note Submitter: daevid@daevid.com ---- I couldn't find anything that did exactly this... Useful for 'alarms' on a web page, where you really care about if they happen on a given day not so much the exact time... function alarmDaysDiff( $year, $month, $day ) { //This function will tell you the proper integer number of days between today and the given date. //dates in the past will be negative, today will be 0, and future dates will be positive //$alarmDate is in standard mySQL format of "YYYY-MM-DD HH:MM:SS" $Y = intval($year); $m = intval($month); $d = intval($day); $diff = ( (mktime(0,0,0,$m,$d,$Y) - mktime(0,0,0,date("m"),date("d"),date("Y"))) / 86400 ) ; if (abs($diff) == $diff) //it's positive so use ceil $diff = ceil($diff); else //it's negative so use floor $diff = floor($diff); //echo "There are ".$diff." days between today & ".$year."-".$month."-".$day."<P>\n"; return $diff; } if ( alarmDaysDiff($year,$month,$day) == 0 ) $alarmmessage .= "This Alarm occurs TODAY."; else if ( alarmDaysDiff($year,$month,$day) < 0 ) $alarmmessage .= "This Alarm is past due."; else if ( alarmDaysDiff($year,$month,$day) <= 7 ) $alarmmessage .= "This Alarm is coming up soon...";

« previous php.notes (#59874) next »