note 65626 added to ref.datetime

From: Date: Thu, 04 May 2006 17:35:54 +0000
Subject: note 65626 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-110557@lists.php.net to get a copy of this message
here's a quick script i used to find recurring dates, it offers some flexibility in how you want to iterate though the dates <?php // ---------------------------------------------------------- // Recurring dates // Returns an array of recurring dates // ---------------------------------------------------------- class recur { var $endOption; // set to either "endBy" or "endAfter" -- endby if you want to end by a date and // end after if you want to end after 'x' amount of occurrences var $endValue; // set to either a date in 'xxxx-xx-xx' format or a number of occurrences var $start; // set to the starting date in 'xxxx-xx-xx' format function interval($type, $spread){ $startDate = explode("-", $this->start); $time = mktime(0, 0, 0, $startDate[1], $startDate[2], $startDate[0]); $dates[] = $this->start; if($this->endOption == "endAfter"){ for($i = 1; $i < $this->endValue; $i++){ $futureTime = strtotime("+$spread $type", $time); $dates[] = date("Y-m-d", $futureTime); $time = $futureTime; } return $dates; }else if($this->endOption == "endBy"){ $endDate = explode("-", $this->endValue); $endTime = mktime(0, 0, 0, $endDate[1], $endDate[2], $endDate[0]); while($endTime > $time){ $futureTime = strtotime("+$spread $type", $time); if($futureTime > $endTime){ break; } $dates[] = date("Y-m-d", $futureTime); $time = $futureTime; } return $dates; } } } ?> example: <?php include("includes/recur.class.php"); $recur = new recur(); $recur->endOption = "endBy"; $recur->endValue = '2006-12-09'; $recur->start = '2006-04-28'; print_r($recur->interval("day", 4)); ?> ---- Server IP: 216.194.113.175 Probable Submitter: 66.18.151.100 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- http://master.php.net/note/edit/65626 Del: integrated -- http://master.php.net/note/delete/65626/integrated Del: useless -- http://master.php.net/note/delete/65626/useless Del: bad code -- http://master.php.net/note/delete/65626/bad+code Del: spam -- http://master.php.net/note/delete/65626/spam Del: non-english -- http://master.php.net/note/delete/65626/non-english Del: in docs -- http://master.php.net/note/delete/65626/in+docs Del: other reasons-- http://master.php.net/note/delete/65626 Reject -- http://master.php.net/note/reject/65626 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110557) next »