note 100181 modified in function.strtotime by danbrown

From: Date: Wed, 29 Sep 2010 20:03:59 +0000
Subject: note 100181 modified in function.strtotime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172824@lists.php.net to get a copy of this message
If you're trying to make Saturday (or any other day for that matter) the first day of the week to select datasets, here's a good workaround: <?php $last_sat=date("z", strtotime("last Saturday")); $second_last_sat=date("z", strtotime("last Saturday-1 week")); ?> then just query your database like so: select everything since last saturday: SELECT whatever.whatever from wherever WHERE DAYOFYEAR(complete) <= DAYOFYEAR(CURDATE()) AND DAYOFYEAR(complete) > ".$last_sat." the week before (beginning on a saturday): SELECT whatever.whatever from wherever WHERE DAYOFYEAR(complete) <= ".$last_sat." AND DAYOFYEAR(complete) > ".$second_last_sat." Good luck! --was-- If you're trying to make Saturday (or any other day for that matter) the first day of the week to select datasets, here's a good workaround: $last_sat=date("z", strtotime("last Saturday")); $second_last_sat=date("z", strtotime("last Saturday-1 week")); then just query your database like so: //select everything since last saturday SELECT whatever.whatever from wherever WHERE DAYOFYEAR(complete) <= DAYOFYEAR(CURDATE()) AND DAYOFYEAR(complete) > ".$last_sat." //the week before (beginning on a saturday) SELECT whatever.whatever from wherever WHERE DAYOFYEAR(complete) <= ".$last_sat." AND DAYOFYEAR(complete) > ".$second_last_sat." Good luck! http://php.net/manual/en/function.strtotime.php

« previous php.notes (#172824) next »