Tuesday 29 May 2012

A lot of people who use Javacsript come up against the same problem when it comes to dates. Stack Overflow is full of these questions. Well look no more...

A quick prototype over the Date object will allow you to add days to a date. By all means extend this or create your own functions such as addMonth, addHour etc using getMonth, getTime and so on.







Date.prototype.addDays = function(days)
{
var dat = new Date(this.valueOf())
dat.setDate(dat.getDate() + days);
return dat;
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.