note 88776 modified in function.date by danbrown

From: Date: Sat, 07 Feb 2009 00:48:44 +0000
Subject: note 88776 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150330@lists.php.net to get a copy of this message
Another slight adaptation from the code posted earlier that you might find slightly more useful. http://us2.php.net/manual/en/function.date.php#87975 Takes a unix timestamp and returns the beginning or end of that week as a unix timestamp. If no timestamp is provided the current time is used. <?php function weekStart($time = null) { if($time == null) $time = time(); $sun = 0; //sunday = start of week $dayOfWeek = date('w', $time); $days_from_sun = $dayOfWeek - $sun; return $time - $days_from_sun * 24 * 60 * 60; } function weekEnd($time = null) { if($time == null) $time = time(); $sat = 6; //saturday = end of week $dayOfWeek = date('w', $time); $days_until_sat = $sat - $dayOfWeek; return $time + $days_until_sat * 24 * 60 * 60; } ?> --was-- Another slight adaptation from the code posted earlier that you might find slightly more useful. http://us2.php.net/manual/en/function.date.php#87975 Takes a unix timestamp and returns the beginning or end of that week as a unix timestamp. If no timestamp is provided the current time is used. function weekStart($time = null) { if($time == null) $time = time(); $sun = 0; //sunday = start of week $dayOfWeek = date('w', $time); $days_from_sun = $dayOfWeek - $sun; return $time - $days_from_sun * 24 * 60 * 60; } function weekEnd($time = null) { if($time == null) $time = time(); $sat = 6; //saturday = end of week $dayOfWeek = date('w', $time); $days_until_sat = $sat - $dayOfWeek; return $time + $days_until_sat * 24 * 60 * 60; } http://php.net/manual/en/function.date.php

« previous php.notes (#150330) next »