Blog

« Back

Calculate working days from date

Author: Milen Hristov
Created on: 02.05.2014 13:17

Simple solution to add working days to a date. We presume that the non working days are only weekends.

PHP solution

<?php
# Get day of week for date 2014-04-29 (Example date)
$dow = date('N', mktime(0, 0, 0, 4, 29, 2014) );

# Define how many working days we need to add
$days = 4;

# Get how many days we realy need to add
$add = $days - (( $dow + $days ) % 5 ? 0 : 2) + ( ( $dow + $days ) - ( $dow + $days ) % 5 ) / 5 * 2;

print "We need to add $add days";

?>




No comments

Comments

Name

E-mail

Comment

Enter the text from the image

Blog tags