note 30976 added to function.mktime

From: Date: Fri, 04 Apr 2003 22:47:45 +0000
Subject: note 30976 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-46243@lists.php.net to get a copy of this message
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..."; -- http://www.php.net/manual/en/function.mktime.php http://master.php.net/manage/user-notes.php?action=edit+30976 http://master.php.net/manage/user-notes.php?action=delete+30976 http://master.php.net/manage/user-notes.php?action=reject+30976

« previous php.notes (#46243) next »