note 62402 deleted from function.mktime by bjori

From: Date: Thu, 01 Jun 2006 18:38:44 +0000
Subject: note 62402 deleted from function.mktime by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112808@lists.php.net to get a copy of this message
Note Submitter: ajaypal at NOSPAM dot ajaypal dot com ---- <?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

« previous php.notes (#112808) next »