Hi All,
I found and have been using this function to get the dates for the past week, which was working ok, until the new year started.
function LastWeek(){
$week = date('W');
$year = date('Y');
$lastweek=$week-1;
if ($lastweek==0){
$week = 52;
$year--;
}
$lastweek=sprintf("%02d", $lastweek);
for ($i=0;$i<=6;$i++){
$arrdays[] = strtotime("$year". "W$lastweek"."$i");
}
return $arrdays;
}
$days = LastWeek();
//show a test of it
echo "last week between " . date('Ymd000000',$days[0])
. " (" . date('m-d-Y',$days[0]) . ") and " . date('Ymd235959', $days[6]) .
" (" . date('m-d-Y',$days[6]) . ")<br><br>";
//query from last weeks dates
$query = "SELECT
COUNT(DISTINCT(EmailAddress)) as total
FROM table
WHERE Active=1";
$query .= " AND Date>='" . date('Y-m-d',$days[0]) . "'
AND Date<='" . date('Y-m-d',$days[6]) . "'";
With the above echo, I am getting:
last week between 19691231000000 (12-31-1969) and 19691231235959 (12-31-1969)
I don't understand why it will not work with last weeks dates when we started a new year?
Thanks for the assistance,
Don