Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strtotime incrementing by weekdays

Tags:

php

strtotime

Today is Friday, April 17, 2015. In my app, it automatically generated a "due date" for each assignment. It's set to "5 business days". To accomplish this, We use:

date('m/d/Y', strtotime("+5 weekdays"));

However, today, this output "04/26/2015". Why? That's a sunday. Why doesn't it give me the 24th, which is what I want?

DEMO: http://codepad.org/2wvnypOC

P.S. After speaking to my boss, we switched to strtotime("+5 days"), but I'm still curious what was wrong with "weekdays".

like image 615
Rocket Hazmat Avatar asked Apr 17 '15 19:04

Rocket Hazmat


1 Answers

It's a bug.

It has been fixed in >= 5.5.0.

So you'll need to work around it or upgrade your php version.

<?php
$today = strtotime('2015-04-17 00:00:00');

echo date('m/d/Y', strtotime("+5 weekdays", $today));
echo "\n";
echo phpversion( );
?>

Working in 5.6*

like image 196
deW1 Avatar answered Sep 18 '22 06:09

deW1