0

I found the current day as Mar 27 2012 ....

var currentday = currentday.format("mmm d yyyy");

I want to find the add three days with this value.
i.e. i need the output as Mar 30 2012.

I also need to find the starting and ending date of a calendar. i.e. Feb 26 2012 - Mar 31 2012 to display the current month as displaying in calendar month view.

Can any one help me on this please....

saran
  • 595
  • 5
  • 17
  • 28

4 Answers4

1
var currentday = new Date();
var nextDay = new Date();
nextDay.setDate(currentday.getDate() + 4);
Craig
  • 6,869
  • 3
  • 32
  • 52
  • alert(nextDay.setDate(currentday.getDate() + 4)); returns "1333191873209", how to convert it into Mar 31 2012 format. Please help me. Thanks – saran Mar 27 '12 at 11:05
  • @saran for date formatting, have a look at [this post](http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript). There is no built in way to format a date if you need the day & month names. – Craig Mar 27 '12 at 11:44
  • @saran The quick and dirty for what you want is `var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"); alert(months[nextDay.getMonth()] + " " + nextDay.getDate() + " " + nextDay.getFullYear());` – Craig Mar 27 '12 at 12:53
0
//Set number of days you want to compute to
var days=4;

//Get current date or whatever date you want to compute from
var currentDate=new Date();

var nDaysFromNow=new Date();
nDaysFromNow.setDate(currentDate.getDate()+days);
Francisc
  • 77,430
  • 63
  • 180
  • 276
-1

You can add days using the getDate() function like so:

var someDate = new Date();
someDate = someDate.getDate() + 3;
davidethell
  • 11,708
  • 6
  • 43
  • 63
  • i got the output as "1333191873209", how to convert it into Mar 31 2012 format. Please help me. Thanks – saran Mar 27 '12 at 11:56
-2

See code below.. Hope it helps

var days = 4;
var next = new Date((new Date).getTime() +  ((1000*3600*24) *days));
David Mulder
  • 26,123
  • 9
  • 51
  • 114
William Calvin
  • 625
  • 6
  • 19