Jump to content

Trying to find the last working day of the month


Icebergness

Recommended Posts

Hi,

 

As the title says, I'm trying to get the last working day of the month (by this I mean excluding Saturday and Sunday). My thinking was that I basically need to this:

 

If (day = Sat)

  {

      -1 day

  }

elseif (day = Sun)

  {

    -2 days

  }

else

  {

    keep it as it is

  }

 

So far, all I have is the below to echo out the day of date("t/m/y"), however, all I'm getting is Thursday, whereas the last day of March is a Saturday

 

<?php

$lastdateofthemonth = date("t/m/y");
$lastworkingday = date('l', strtotime($lastdateofthemonth));
echo $lastworkingday; 

?>

 

Can anyone help, or point me in the way of where this may have been answered in the past? I've searched all over Google but can't find what I'm looking for.

 

Thanks

in case you're still fighting it - here's what I came up with.

$lastdateofthemonth = date("Y-m-t");

$lastworkingday = date('l', strtotime($lastdateofthemonth));

if($lastworkingday == "Saturday") { 
$newdate = strtotime ('-1 day', strtotime($lastdateofthemonth));
$lastworkingday = date ('Y-m-j', $newdate);
}
elseif($lastworkingday == "Sunday") { 
$newdate = strtotime ('-2 day', strtotime($lastdateofthemonth));
$lastworkingday = date ( 'Y-m-j' , $newdate );
}

echo date('l', strtotime($lastworkingday))." ".$lastworkingday;

 

That should get you what you're after... :) Good luck!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.