I have this string
var start = $('[name=invoicedate]').val();
alert('start'); // 2010/01/01
how can I add five days to have the following?
alert('start'); // 2010/01/10
Tried
var start = new Date(year, month, day+5);
but seems not work
add 5 days to a string
Moderator: General Moderators
Re: add 5 days to a string
You might use strtotime().
http://www.w3schools.com/php/func_date_strtotime.asp
[Edit:] Oops, I wasn't paying attention. You can use PHP's strtotime() function if you are building the Javascript using PHP, but of course not if you must do this after the page has been sent to the browser! Sorry for my hasty answer.
http://www.w3schools.com/php/func_date_strtotime.asp
[Edit:] Oops, I wasn't paying attention. You can use PHP's strtotime() function if you are building the Javascript using PHP, but of course not if you must do this after the page has been sent to the browser! Sorry for my hasty answer.
Last edited by califdon on Wed Mar 09, 2011 11:56 am, edited 1 time in total.
Reason: Realized that this is Javascript!
Reason: Realized that this is Javascript!
Re: add 5 days to a string
First we extend the Date object:
Then use addDays whenever you want:
Code: Select all
Date.prototype.addDays = function (days)
{
this.setDate(this.getDate() + days);
}Code: Select all
var start = '2010/01/31';
startDate = new Date(start);
startDate.addDays(5);
alert(startDate);There are 10 types of people in this world, those who understand binary and those who don't