note 78827 deleted from function.date by danbrown

From: Date: Sun, 20 Jul 2008 02:47:17 +0000
Subject: note 78827 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141986@lists.php.net to get a copy of this message
Note Submitter: info at NOSPAM dot ogmatter dot com ---- Hello, these notes have been very helpful and help me solve the following problem. I have a db with scheduled items that contain a start date, a day to occur on and how many weeks from the next closest day to happen again. I wrote the following script to do the following 1. Accept : starting date, the current date, the number of weeks between occurances and the day of the week it is to occur on. 2. Find the closest future day of the week argument from the start date. 3. Find out when the next time the item should happen via the weeks inbetween and the closest day of the week to the start date. The result could be compared with your current date to trigger your periodical item or simply to find out when the next occurances will happen. // $startDate:Date // $todayDate:Date // $weeks:Int - number of weeks in between // $wantDay:String - full day of the week function getWeekPeriodDate($startDate,$todayDate,$weeks,$wantDay){ $startDate = date("Y-m-d", strtotime("next $wantDay" ,strtotime($startDate))); $dayDiff = round((strtotime($startDate)-strtotime($todayDate))/(24*60*60),0); $weekPeriodDiff = abs(round($dayDiff/7/$weeks)*$weeks); return date("Y-m-d",strtotime($startDate . " + " . $weekPeriodDiff . " weeks")); } Usage :getWeekPeriodDate("2006-July-1","2007-Nov-5",8,"Tuesday") returns : 2007-11-20 (which is the next Tuesday based on 8 week periods since the next Tuesday closest to the start date)

« previous php.notes (#141986) next »