Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php first and last weekday (workable Mon-Fri) of month using simple strtotime

Solved! i leave it here for you.

This two lines of code are ok for the first workable day:

date('d-m-Y',strtotime('+0 weekdays October 2016'))

Returns : 3-10-2016 --> OK

date('d-m-Y', strtotime('weekday february 2016'))

Returns : 1-2-2016 --> OK

The last workable day of a given month and year:

$year=2016;
$month='october';
$lastworkable=date('d-m-Y', strtotime('last weekday '.date("F Y", strtotime('next month '.$month.' '.$year))));

Returns : 29-07-2016 for july --> OK

like image 352
Jonathan Orrego Avatar asked Jul 21 '16 16:07

Jonathan Orrego


1 Answers

I hope this one will help you

Edit 1

  <?php echo date('d-m-Y',strtotime("last Monday of July 2016")); //25-07-2016
   echo date('d-m-Y',strtotime("last Monday of October 2016")); //31-10-2016

Edit 2

Sure this will help you

echo date('Y-m-d', strtotime('2016-09-01 first weekday'));
like image 143
I'm Geeker Avatar answered Oct 19 '22 20:10

I'm Geeker