note 77489 added to function.strftime

From: Date: Fri, 31 Aug 2007 13:43:39 +0000
Subject: note 77489 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-129942@lists.php.net to get a copy of this message
A small function to get the first weekday of the month. For example the first monday of the month, or the first friday, etc. <?php /** * * Gets the first weekday of that month and year * * @param int The day of the week (0 = sunday, 1 = monday ... , 6 = saturday) * @param int The month (if false use the current month) * @param int The year (if false use the current year) * * @return int The timestamp of the first day of that month * **/ function get_first_day($day_number=1, $month=false, $year=false) { $month = ($month === false) ? strftime("%m"): $month; $year = ($year === false) ? strftime("%Y"): $year; $first_day = 1 + ((7+$day_number - strftime("%w", mktime(0,0,0,$month, 1, $year)))%7); return mktime(0,0,0,$month, $first_day, $year); } // this will output the first wednesday of january 2007 (wed 03-01-2007) echo strftime("%a %d-%m-%Y", get_first_day(3, 1, 2007)); ?> ---- Server IP: 83.137.20.107 Probable Submitter: 82.204.37.70 ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- https://master.php.net/note/edit/77489 Del: integrated -- https://master.php.net/note/delete/77489/integrated Del: useless -- https://master.php.net/note/delete/77489/useless Del: bad code -- https://master.php.net/note/delete/77489/bad+code Del: spam -- https://master.php.net/note/delete/77489/spam Del: non-english -- https://master.php.net/note/delete/77489/non-english Del: in docs -- https://master.php.net/note/delete/77489/in+docs Del: other reasons-- https://master.php.net/note/delete/77489 Reject -- https://master.php.net/note/reject/77489 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129942) next »