0

I've looked around and cant find a very elegant solution for this. If I have a timestamp, is there an elegant way to add a X number of business days to it? I've found solutions that calculate business days between two dates and some implementations in C++ and C# but nothing exactly like this for PHP.

I've been told strtotime is able to handle it with limited efficacy but I do need it to be accurate so I'd like to avoid that.

Thanks!

Pharm
  • 152
  • 1
  • 12
  • The code you've found for business days will take you most of the way there. Plus you need to figure out how you're going to handle holidays. – John Conde Nov 14 '13 at 02:07
  • http://www.php.net/manual/en/datetime.add.php – Funk Forty Niner Nov 14 '13 at 02:08
  • @JohnConde I'm not worried about holidays, infact I'd ignore them. I'm more concerned about just saturday and sundays. – Pharm Nov 14 '13 at 02:20
  • @Fred-ii- I looked around but didn't find anything in the PHP manual about business days in particular with the add method. – Pharm Nov 14 '13 at 02:21
  • 2
    [This really does most of the work for you](http://stackoverflow.com/questions/336127/calculate-business-days) – John Conde Nov 14 '13 at 02:28
  • Look into the [`date()`](http://www.php.net/manual/en/function.date.php) function where you can grab & differentiate from Sunday through Saturday. There are many ways to go about this, am sure. For example `$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("Y"));` and [this answer on SO](http://stackoverflow.com/a/712923/1415724) and I quote from one of the comments: "Since php 5.1.0 you can use date("N", $timestamp) to get 1..7 values starting from Monday. In the older versions you can use the trick (date("w", $timestamp) + 6) % 7 to get 0..6 values starting from Monday." @user2988034 – Funk Forty Niner Nov 14 '13 at 03:17

0 Answers0