php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62211 Weekdays with strtotime
Submitted: 2012-06-02 01:55 UTC Modified: 2012-06-02 09:18 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alix dot axel at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alix dot axel at gmail dot com
New email:
PHP Version: OS:

 

 [2012-06-02 01:55 UTC] alix dot axel at gmail dot com
Description:
------------
When using the relative "weekday[s]" string with strtotime() it returns 
inconsistent results, sometimes the date is the correct one, but some other times 
it's wrong (it even returns weekend days).

http://codepad.org/2wYfJltN
http://stackoverflow.com/questions/10857762/php-time-periods-without-weekends

Test script:
---------------
<?php

var_dump(PHP_VERSION);

$date = strtotime('2012-05-30'); // Wednesday

var_dump(date('Y-m-d (l)', strtotime('+1 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+6 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+8 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+9 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+10 weekdays', $date)));

$date = strtotime('2012-05-31'); // Friday

var_dump(date('Y-m-d (l)', strtotime('+1 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+6 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+8 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+9 weekdays', $date)));
var_dump(date('Y-m-d (l)', strtotime('+10 weekdays', $date)));

Expected result:
----------------
string(5) "5.2.5"
string(21) "2012-05-31 (Thursday)"
string(21) "2012-06-07 (Thursday)"
string(21) "2012-06-11 (Monday)"
string(19) "2012-06-12 (Tuesday)"
string(22) "2012-06-13 (Wednesday)"
string(19) "2012-06-01 (Friday)"
string(19) "2012-06-08 (Friday)"
string(19) "2012-06-12 (Tuesday)"
string(19) "2012-06-13 (Wednesday)"
string(21) "2012-06-14 (Thursday)"

Actual result:
--------------
string(5) "5.2.5"
string(21) "2012-05-31 (Thursday)"
string(21) "2012-06-07 (Thursday)"
string(21) "2012-06-09 (Saturday)"
string(19) "2012-06-10 (Sunday)"
string(22) "2012-06-13 (Wednesday)"
string(19) "2012-06-01 (Friday)"
string(19) "2012-06-08 (Friday)"
string(19) "2012-06-10 (Sunday)"
string(19) "2012-06-11 (Monday)"
string(21) "2012-06-14 (Thursday)"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-02 09:18 UTC] rasmus@php.net
Please use a current version of PHP. 5.2.5 is from 2007. 
This is the output I get:

string(10) "5.3.15-dev"
string(21) "2012-05-31 (Thursday)"
string(21) "2012-06-07 (Thursday)"
string(19) "2012-06-11 (Monday)"
string(20) "2012-06-12 (Tuesday)"
string(22) "2012-06-13 (Wednesday)"
string(19) "2012-06-01 (Friday)"
string(19) "2012-06-08 (Friday)"
string(20) "2012-06-12 (Tuesday)"
string(22) "2012-06-13 (Wednesday)"
string(21) "2012-06-14 (Thursday)"
 [2012-06-02 09:18 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 22:01:30 2024 UTC