note 84166 deleted from function.strtotime by googleguy

From: Date: Tue, 22 Oct 2013 08:02:27 +0000
Subject: note 84166 deleted from function.strtotime by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196754@lists.php.net to get a copy of this message
Note Submitter: enkrs ---- It is worth noting, that strtotime() accepts ISO week date format (for example "2008-W27-2" is Tuesday of week 27 in 2008), so it can be easily used to get the date of a given week number. <?php function week($year, $week) { $from = date("Y-m-d", strtotime("{$year}-W{$week}-1")); //Returns the date of monday in week $to = date("Y-m-d", strtotime("{$year}-W{$week}-7")); //Returns the date of sunday in week return "Week {$week} in {$year} is from {$from} to {$to}."; } echo week(2008,27); //Returns: Week 27 in 2008 is from 2008-06-30 to 2008-07-06. ?>

« previous php.notes (#196754) next »