Hey guys,
I am trying to determine the last week’s monday in the format: month DD, YYYY HH:MM:SS. Thus, I came up with this function:
[code=php]
/******************************************************/
/* GETLASTWEEKDAY *************************************/
/******************************************************/
/* FORMAT: HOW THE DAY IS SUPPOSED TO LOOK ************/
/******************************************************/
function getLastWeekDay($format) {
$day = date(“w”);
/* SET DATE TO A WEEK AGO FROM THE LAST MONDAY */
switch ($day) {
case ‘1’:
/* MONDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+0))).” 00:00:00″);
break;
case ‘2’:
/* TUESDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+1))).” 00:00:00″);
break;
case ‘3’:
/* WEDNESDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+2))).” 00:00:00″);
break;
case ‘4’:
/* THURSDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+3))).” 00:00:00″);
break;
case ‘5’:
/* FRIDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+4))).” 00:00:00″);
break;
case ‘6’:
/* SATURDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+5))).” 00:00:00″);
break;
case ‘0’:
/* SUNDAY */
$lastWeek = date($format, (time()-(60*60*24*(7+6))).” 00:00:00″);
break;
}
return $lastWeek;
}
It’s fairly simple, but I was wondering how other people did it, if there is a better way, etc.
I looked at some calendar functions, namely JDDayOfWeek(), but I couldn’t come up with a way to use it either without using a switch statement. I tested it for today, it works fine, so I can’t think anything other than it working for the other days. But if you guys have a better way, I’m interested.
Jaelan