I want to date object of last 6th week date from the current date.
var cuurrentDate = new Date();
Ex. Current date:
Jul 06 2016 hh:mm:ss GMT+0530 (Indian Standard Time)
I want to display the date of last 6th week:
Output:
May 25 2016 hh:mm:ss GMT+0530 (Indian Standard Time)
Use Date.setDate()
and subtract number of days from current date
var date = new Date(); var d = date.getDate(); var numOfWeeks = 6; date.setDate(d - (numOfWeeks * 7)); console.log(date);
Assuming by last 6th week, you mean exactly 6 * 7 days ago (42).
You can modify the date instance using the setDate
method, passing it the current instance's getDate
subtracted by 42 days. For example:
var d = new Date();
d.setDate(d.getDate() - 42);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.