Hi,
I need to get previous day from an existing date stored in a varaible $date which will not include any weekend (saturday and sunday)
if it is on monday date should be for friday
How can I do this??
Thanks,
Jas
Hi Jas,
This is how I would do it. I think you can probably replace the switch with a loop to make it more elegant but this will work as it is:
[php]
<?php
$lcYesterday = mktime(0, 0, 0, date("m") , date("d")-1, date("Y"));
switch (date('N',$lcYesterday))
{
case "6": // yesterday was Saturday, today is Sunday so it's 2 days back to Friday
$lcLastWorkingDay = mktime(0, 0, 0, date("m") , date("d")-2, date("Y"));
break ;
case "7": // yesterday was Sunday, today is Monday so it's 3 days back to Friday
$lcLastWorkingDay = mktime(0, 0, 0, date("m") , date("d")-3, date("Y"));
break;
default:
$lcLastWorkingDay = $lcYesterday ;
}
echo date('l' , $lcLastWorkingDay) ;
?>
[/php]
I hope this helps
nathj