|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-11-14 16:44 UTC] padre dot cedano at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/datetime.modify --- If i try this today, 2o17-11-14: modify('last monday this week') the result is: 06/11/2017 But last monday this week was: 13/11/2017 Test script: --------------- <?php function getLastDayofWeek ($strDia){ $date=new DateTime('now'); $strCriterio='last '.$strDia.' this week'; $date->modify($strCriterio); echo $strCriterio.": ".$date->format('d/m/Y').PHP_EOL; } /*Pruebas*/ getLastDayofWeek('monday'); getLastDayofWeek('saturday'); getLastDayofWeek('sunday'); ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 08:00:01 2025 UTC |
Ok. My function is working as: function getLastDayofWeek ($strDia){ $date=new DateTime('now'); $strCriterio='last '.$strDia; $d=$date->modify($strCriterio); echo $strCriterio.":\t ".$d->format('d/m/Y').PHP_EOL; } Result: last monday: 13/11/2017 last tuesday: 14/11/2017 last wednesday: 08/11/2017 last thursday: 09/11/2017 last friday: 10/11/2017 last saturday: 11/11/2017 last sunday: 12/11/2017 But is not working if i pass the $date as parameter: function getLastDayofWeekFake ($strDia,$date){ $strCriterio='last '.$strDia; $d=$date->modify($strCriterio); echo $strCriterio.":\t ".$d->format('d/m/Y').PHP_EOL; } Result: last monday: 13/11/2017 last tuesday: 07/11/2017 last wednesday: 01/11/2017 last thursday: 26/10/2017 last friday: 20/10/2017 last saturday: 14/10/2017 last sunday: 08/10/2017 Why is not working in second function?