note 62402 added to function.mktime

From: Date: Mon, 27 Feb 2006 21:51:50 +0000
Subject: note 62402 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-104515@lists.php.net to get a copy of this message
<?php /** Finds and Returns the timestamp of Given WeekDay just before a given date (as timestamp) Arguments: $weekdaytofind defaults to monday: 0->sun, 1->mon,2->tue etc... weekday for which you are looking for $givenDateTimestamp date before which you want the weekday date */ function getTimestampOfPrevWeekDayFromGivenDate($weekdaytofind = 1, $givenDateTimestamp = 0) { if(!$givenDateTimestamp) { //Build Today $tmonth=date('n'); $tday=date('d'); $tyear=date('Y'); } else { $tmonth=date('n', $givenDateTimestamp); $tday=date('d', $givenDateTimestamp); $tyear=date('Y', $givenDateTimestamp); } //convert it to unix timestamp, just in case it may be invalid $ts = mktime(0, 0, 0,$tmonth,$tday,$tyear); for($weekday=date("w", $ts); $weekday != $weekdaytofind; $weekday=date("w", $ts)) { //easy way to adjust $tmonth=date('n', $ts); $tday=date('d', $ts); $tyear=date('Y', $ts); //convert it to unix timestamp $ts = mktime(0, 0, 0, $tmonth, $tday-1, $tyear); } return $ts; } ?> Feel free to optimise ---- Server IP: 203.199.124.111 Probable Submitter: 203.134.192.170 ---- 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/function.mktime.php Edit -- http://master.php.net/note/edit/62402 Del: integrated -- http://master.php.net/note/delete/62402/integrated Del: useless -- http://master.php.net/note/delete/62402/useless Del: bad code -- http://master.php.net/note/delete/62402/bad+code Del: spam -- http://master.php.net/note/delete/62402/spam Del: non-english -- http://master.php.net/note/delete/62402/non-english Del: in docs -- http://master.php.net/note/delete/62402/in+docs Del: other reasons-- http://master.php.net/note/delete/62402 Reject -- http://master.php.net/note/reject/62402 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104515) next »