Obtain the date of the previous n days or the next n days

Source: Internet
Author: User
Tags diff echo date

Obtain the date of the previous n days or the next n days
 
The following describes three implementations: calculate the date before n days and obtain the N days before the specified date. Finally, there is a js code.
$ Rs ['expire _ long'] = 5;
Echo date ("Y-m-d H: I: s", strtotime ('-'. $ rs ['expire _ long']. 'Days ', strtotime ('2017-01-01 10:28:18 ')));


<?
// ========= Calculate the date subolddate () =====================
Function subolddate ($ day ){
$ Now = time ();
$ M = $ day * 24*60*60;
$ Diff = $ now-$ m;
$ Oldday = date ("Y-m-d", $ diff );
Echo $ day. "days before". $ oldday;
}  
// ================================================ ============================
Subolddate (5 );
?> ?

Js implementation method

<Script type = "text/webpage effects">
Function showdate (n)
{
Var uom = new Date ()-0 + n * 86400000 );
Uom = uom. getFullYear () + "-" + (uom. getMonth () + 1) + "-" + uom. getDate ();
Return uom;
}

Window. alert ("today is:" + showdate (0 ));
Window. alert ("yesterday:" + showdate (-1 ));
Window. alert ("Tomorrow is:" + showdate (1 ));
Window. alert ("10 days ago:" + showdate (-10 ));
Window. alert ("5 days later:" + showdate (5 ));
</Script>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.