Skip to content

Instantly share code, notes, and snippets.

@thorne51
Created July 29, 2015 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thorne51/dc29cf4c660395048ac2 to your computer and use it in GitHub Desktop.
Save thorne51/dc29cf4c660395048ac2 to your computer and use it in GitHub Desktop.
Simple test to see what strtotime produces with 31st of a month going back in months with february which only has 28/29 days
<?php
echo '2015-07-28 -5 month: ' . date('Y-m-d', strtotime('2015-07-28 -5 month')) . "\r\n";
echo '2015-07-29 -5 month: ' . date('Y-m-d', strtotime('2015-07-29 -5 month')) . "\r\n";
echo '2015-07-30 -5 month: ' . date('Y-m-d', strtotime('2015-07-30 -5 month')) . "\r\n";
echo '2015-07-31 -5 month: ' . date('Y-m-d', strtotime('2015-07-31 -5 month')) . "\r\n";
@thorne51
Copy link
Author

Output:

2015-07-28 -5 month: 2015-02-28
2015-07-29 -5 month: 2015-03-01
2015-07-30 -5 month: 2015-03-02
2015-07-31 -5 month: 2015-03-03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment