I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.
I'm a novice and trying hard to learn.
I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.
I'm a novice and trying hard to learn.
You can use JavaScript, no jQuery required:
var someDate = new Date();
var numberOfDaysToAdd = 6;
someDate.setDate(someDate.getDate() + numberOfDaysToAdd);
Formatting to dd/mm/yyyy :
var dd = someDate.getDate();
var mm = someDate.getMonth() + 1;
var y = someDate.getFullYear();
var someFormattedDate = dd + '/'+ mm + '/'+ y;
You could extend the javascript Date object like this
Date.prototype.addDays = function(days) {
var newDate = new Date((this.valueOf() + (days * 86400000)));
return newDate;
};
and in your javascript code you could call
var currentDate = new Date();
// to add 4 days to current date
currentDate.addDays(4);
You can use this library "Datejs open-source JavaScript Date Library".
A suggestion: DON'T use milliseconds, or maybe daylight-saving-time will occur.