note 14268 deleted from function.date by jimw

From: Date: Fri, 02 Nov 2001 01:11:32 +0000
Subject: note 14268 deleted from function.date by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20094@lists.php.net to get a copy of this message
Here's a little script I made up to find the datestamp for the first/last day of whatever week. I needed this to calculate interest rates for transactions occuring within this time period. You could put in any date into these functions and have it give you the sunday of that week, and the saturday of that week.. <?php header("Content-Type: text/plain"); function firstDayOfWeek ( $year, $month, $day ) { $dayOfWeek=date("w"); $sunday_offset=$dayOfWeek * 60 * 60 * 24 ; return date("Y-m-d", mktime(0,0,0,$month,$day,$year) - $sunday_offset); } function lastDayOfWeek ( $year, $month, $day ) { $dayOfWeek=date("w"); $saturday_offset=(6-$dayOfWeek) * 60 * 60 * 24 ; return date("Y-m-d", mktime(0,0,0,$month,$day,$year) + $saturday_offset); } echo "First day of week of 2001-07-31 is " . firstDayOfWeek( "2001", "07", "31" ) . "\n"; echo "Last day of week of 2001-07-31 is " . lastDayOfWeek( "2001", "07", "31" ); ?>

« previous php.notes (#20094) next »