Skip to content

Instantly share code, notes, and snippets.

@tamewhale
Created January 11, 2012 10:36
Show Gist options
  • Save tamewhale/1594092 to your computer and use it in GitHub Desktop.
Save tamewhale/1594092 to your computer and use it in GitHub Desktop.
Calculate date X working days from now
<?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