Created
January 11, 2012 10:36
-
-
Save tamewhale/1594092 to your computer and use it in GitHub Desktop.
Calculate date X working days from now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// accepts a DateTime object which is now by default | |
// and returns a DateTime object x working days from now | |
// where x defaults to 1 | |
function get_next_working_day($date = new DateTime, $no_of_days = 1) { | |
// add the number of days passed but skip weekends | |
for ($i = 0; $i < $no_of_days; $i++) { | |
do { | |
$date::add(new DateInterval('P1D')); | |
} | |
while (in_array($date->format('D'), array('Sat', 'Sun'))); // keep adding if day is a Saturday or Sunday | |
} | |
return $date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment