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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 + 3 = ?
Subscribe to this entry?

 
 [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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC