0

Mates, I'm trying to make a hostel booking reservation calendar on a Backbone application. I need to make week intervals to make the calendar, but the thing is that, having a YYYY-MM-DD date, i don't know how to increment day by day, knowing how many days has each month.

Anyone has an idea?

Thanks a lot!

Pablo
  • 1,173
  • 4
  • 18
  • 46
  • check out this: http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript – Jaiwo99 Feb 23 '13 at 00:00
  • This is beyond vague, but all you really need to get started is https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date – Matt Ball Feb 23 '13 at 00:04

1 Answers1

1

Using just the javascript Date object you can increment similar to this:

var dayIncrement = 24 * 60 * 60 * 1000; // one day in milliseconds
var startDate = new Date('2013-03-01 00:00:00');
var startDateMillis = startDate.getTime();
var startDatePlusOne = new Date(startDateMillis + dayIncrement);

var weekIncrement = dayIncrement * 7;
var startDatePlusWeek = new Date(startDateMilis + weekIncrement);

There are a number of other libraries out there like DateJS that give more robust features.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103