Known Date: 2013-07-31 plus 12 months 3 months 1 months get the appropriate date

Source: Internet
Author: User
Known Date: 2013-07-31 plus 12 months 3 months 1 months get the appropriate date

How can daniel write php code?


Reply to discussion (solution)

!--? php

$date 1 = "2006-08-09";
Echo Date (' y-m-d ', Strtotime ("$date 1 +5 Day")), or, accordingly, to increase the month, the year, or the day to months or years
?>
Output: 2006-08-14

+++++++++++++ today, Yesterday, tomorrow, last week, next week +++++++++++++++

!--? php
date_default_timezone_set (' PRC '); Date ("y-m-d", "Time ()"), "
" in the TimeZone
Echo today:
echo "Yesterday:", Date ("Y-m-d", Strtotime ("1 day"), "
";
echo "Tomorrow:", Date ("Y-m-d", Strtotime ("+1 Day"), "
";
Echo "One week later:", Date ("Y-m-d", Strtotime ("+1 Week"), "
";
echo "2 days, four hours, two seconds after the week:", Date ("Y-m-d g:h:s", Strtotime ("+1 Week 2 Day 4 hours 2 Seconds"), "
";
Echo "Next week Four:", Date ("Y-m-d", Strtotime ("next Thursday")), "
";
echo "Last Monday:". Date ("y-m-d", "Strtotime"). "
";
echo "One months ago:". Date ("Y-m-d", Strtotime ("Last month"). "
";
echo "After one months:". Date ("Y-m-d", Strtotime ("+1 Month")). "
";
Echo "Ten years later:". Date ("Y-m-d", Strtotime ("+10 Year")). "
";

?>


$date 1 = "2006-08-09";
echo Date (' y-m-d ', Strtotime ("$date 1 +5 Day"); Accordingly, increase the month, year, Change day to Month
?>
Output Result: 2006-08-14

+++++++++++++ today, yesterday, tomorrow, last week, next week +++++++++++++++

Date_default_timezone_set (' PRC '); Default time zone
echo "Today:", Date ("Y-m-d", Time ()), "
";
echo "Yesterday:", Date ("Y-m-d", Strtotime ("-1 Day")), "
";
echo "Tomorrow:", Date ("Y-m-d", Strtotime ("+1 Day"), "
";
echo "One week later:", Date ("Y-m-d", Strtotime ("+1 Week")), "
";
echo "2 days a week four hours two seconds later:", Date ("Y-m-d g:h:s", Strtotime ("+1 Week 2 Day 4 hours 2 Seconds")), "
";
echo "Next week Four:", Date ("Y-m-d", Strtotime ("next Thursday")), "
";
echo "Previous Monday:". Date ("Y-m-d", Strtotime ("Last Monday")). "
";
echo "One months ago:". Date ("Y-m-d", Strtotime ("Last month"). "
";
echo "One months later:". Date ("Y-m-d", Strtotime ("+1 Month")). "
";
echo "Ten years later:". Date ("Y-m-d", Strtotime ("+10 Year")). "
";

?>
Not this one. To add natural months, some months 28 days. Some 31 days

$s = ' 2013-07-31 ';
echo Date ("Y-m-d", Strtotime ("$s +1 month");

Oh, take it for granted

echo Date ("y-m-d\n", Strtotime ("$s +7 month");
Get 2014-03-03
Select Adddate (' 2013-07-31 ', INTERVAL 7 month)
Get 2014-02-28

Obviously, PHP's performance is unsatisfactory.

Mktime can actually meet the requirements.

$t = ' 2013-07-31 '; Echo date ("Y-m-d", Mktime (0,0,0,date ("M") + 12,date ("D"), Date ("Y")). '
'; Echo date ("Y-m-d", Mktime (0,0,0,date ("M") + 3,date ("D"), Date ("Y")). '
'; Echo date ("Y-m-d", Mktime (0,0,0,date ("M") + 1,date ("D"), Date ("Y")). '
';



Results:
2014-07-312013-10-312013-08-31

$t = ' 2013-07-31 '; Echo date ("Y-m-d", Mktime (0,0,0,date ("M") + 2,date ("D"), Date ("Y"));

To 2013-10-01

The most undesirable is: to avoid contradictions
  • Related Article

    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.