note 14268 added to function.date.php

From: Date: Tue, 24 Jul 2001 19:57:17 +0000
Subject: note 14268 added to function.date.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15786@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" ); ?> http://www.php.net/manual/en/function.date.php

« previous php.notes (#15786) next »