Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript days +/- from today

For a datepicker I need two dates: from: today - 7 days, to: today + 7 days.

I get a currentDate with:

  var toDay = new Date();
  var curr_date = toDay.getDate();
  var curr_month = toDay.getMonth();
  curr_month++;
  var curr_year = toDay.getFullYear();
  var toDay = (curr_month + "/" + curr_date + "/" + curr_year);

How to get 7 days+ and 7 days- dates ? With corresponding month!

like image 575
A1exandr Avatar asked Oct 31 '25 13:10

A1exandr


1 Answers

As per comment, You can use following code

var myDate = new Date();
myDate.setDate(myDate.getDate() + 7);
var nextWeekDate = ((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear());

myDate = new Date();
myDate.setDate(myDate.getDate() -7 );
var prevWeekDate = ((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear());

Modified Demo

like image 93
Satpal Avatar answered Nov 03 '25 03:11

Satpal