|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-04-02 05:49 UTC] ansari dot sohail2013 at gmail dot com
Description:
------------
$d = '30-03-2018';
echo date('Y-m', strtotime('-1 month '.$d));// should give 2018-02
echo date('Y-m', strtotime('-2 month '.$d));// this gives 2018-01
Output:
2018-03
2018-01
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 05:00:01 2025 UTC |
To obtain your expected output, you can use: <?php $d = '30-03-2018'; echo date('Y-m-d', strtotime('last day of -1 month '.$d)), "\n"; echo date('Y-m-d', strtotime('last day of -2 month '.$d)), "\n"; ?> See also "Example #3" at http://php.net/manual/en/datetime.examples-arithmetic.php#example-2530