Time calculation has some questions. List the most recent 6 months before and after

Source: Internet
Author: User
Time calculation problem Ah ... List the most recent 6 months before and after

$arr = Array ();
$nowd = Date ("Ym");
$arr [] = Date ("Ym", Strtotime ("-6 month"));
$arr [] = Date ("Ym", Strtotime ("-5 month"));
$arr [] = Date ("Ym", Strtotime ("-4 Month"));
$arr [] = Date ("Ym", Strtotime ("-3 month"));
$arr [] = Date ("Ym", Strtotime ("-2 Month"));
$arr [] = Date ("Ym", Strtotime ("-1 month"));

$arr [] = Date ("Ym");

$arr [] = Date ("Ym", Strtotime ("+1 Month"));
$arr [] = Date ("Ym", Strtotime ("+2 Month"));
$arr [] = Date ("Ym", Strtotime ("+3 Month"));
$arr [] = Date ("Ym", Strtotime ("+4 Month"));
$arr [] = Date ("Ym", Strtotime ("+5 Month"));
$arr [] = Date ("Ym", Strtotime ("+6 Month"));

for ($i =0; $i <>
echo "". $arr [$i]. ",";
if ($i%3==0)
Echo '
';
}


?>

Print it out in the middle with 2 x 201203

201204 missing ...

Only today 2012 03 31 The whole day when the usual is normal, seeking analysis ...

Please set the date to No. 3.31 if you are testing.

------Solution--------------------
or use your code.

$nowd = Date ("Y-m-1");
The shape is like
$arr [] = Date ("Ym", Strtotime ("-6 month"));
are changed to form as
$arr [] = Date ("Ym", Strtotime ("-6 month $nowd"));
You can do it.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.