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: 2016-03-24 09:37 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: libor at skocik dot cz Assigned:
Status: Open Package: Date/time related
PHP Version: 5.5.33 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: 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

Add a Patch

Pull Requests

Add a Pull Request

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
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 29 07:01:24 2020 UTC