php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71888 format date (Y-W) - problem
Submitted: 2016-03-23 13:10 UTC Modified: 2021-06-24 15:18 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: libor at skocik dot cz Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.5.33 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: libor at skocik dot cz
New email:
PHP Version: OS:

 

 [2016-03-23 13:10 UTC] libor at skocik dot cz
Description:
------------
---
From manual page: http://www.php.net/language.errors
---

Write for date ("Y-W") from strtotime, setISODate.

Test script:
---------------
echo urci_minuly_tyden(2015,2)."-<br /><br /><br />";
echo urci_minuly_tyden2(2015,2)."<br /><br /><br />";

function urci_minuly_tyden($rok,$tyden)
{

    // return date("Y-m-d",strtotime('2015W02 -1 week'));
    return date("Y-W",strtotime('2015W02 -1 week'));

}

function urci_minuly_tyden2($rok,$tyden)
{
    $week_start = new DateTime();
    $week_start->setISODate($rok,$tyden);
    $week_start->modify('-7 days');
    //return $week_start->format('d-m-Y');
    return ($week_start->format('Y-W'));
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-24 09:32 UTC] libor at skocik dot cz
solution code:


echo last_week (2015,2)."<br /><br /><br />";

function last_week($rok,$tyden)
{
    $week_start = new DateTime();
    $week_start->setISODate($rok,$tyden);
    $week_start->modify('-1 week');

    $year=$week_start->format('Y');
    $month=$week_start->format('m');
    $week=$week_start->format('W');

    if ($month=='12' && $week=='01')
    {
        $year=(int)$year+1;
    }
    elseif ($month=='01' && $week=='52')
    {
        $year=(int)$year-1;
    }
    return (string)$year.'-'.$week;
}
 [2016-03-24 09:37 UTC] pajoye@php.net
-Package: date_time +Package: Date/time related
 [2021-06-24 15:18 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-06-24 15:18 UTC] cmb@php.net
Proper solution: "o-W"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 19:01:31 2025 UTC