Next business day of given date in PHP -


does have php snippet calculate next business day given date? how does, example, yyyy-mm-dd need converted find out next business day?

example: 03.04.2011 (dd-mm-yyyy) next business day 04.04.2011. 08.04.2011 next business day 11.04.2011.

this variable containing date need know next business day for

$cubetime['time']; 

variable contains: 2011-04-01 result of snippet should be: 2011-04-04

next weekday

this finds next weekday specific date (not including saturday or sunday):

echo date('y-m-d', strtotime('2011-04-05 +1 weekday')); 

you date variable of course:

$mydate = '2011-04-05'; echo date('y-m-d', strtotime($mydate . ' +1 weekday')); 

want skip holidays?:

although original poster mentioned "i don't need consider holidays", if happen want ignore holidays, remember - "holidays" array of whatever dates don't want include , differs country, region, company, person...etc.

simply put above code function excludes/loops past dates don't want included. this:

$tmpdate = '2015-06-22'; $holidays = ['2015-07-04', '2015-10-31', '2015-12-25']; $i = 1; $nextbusinessday = date('y-m-d', strtotime($tmpdate . ' +' . $i . ' weekday'));  while (in_array($nextbusinessday, $holidays)) {     $i++;     $nextbusinessday = date('y-m-d', strtotime($tmpdate . ' +' . $i . ' weekday')); } 

i'm sure above code can simplified or shortened if want. tried write in easy-to-understand way.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -