Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello all,

I want to add day to date in textbox.
i have asp.net textbox control on page which has date.
Javascript or jquery both solutions are ok to me.

Regards,
SUNIL MALI.
Posted
Comments
Sunasara Imdadhusen 20-May-13 8:34am    
Have tried before????

Hi Sunil,


Use following code: this is jquery code
JavaScript
//Current date is 20 May 2013
var currentDate = new Date();
//I have added 5 days in current date. New date is 25 May 2013
currentDate.setDate(currentDate.getDate()+5);
//I have setting new date to textbox e.g. txtDate is a id of textbox or date picker
$('#txtDate').val(currentDate);


Following are updated solution
If the value of the textbox is something like "05/21/2013", you should be able to use:
JavaScript
var currentDate = new Date($('#<%= txtDate.ClientID %>').val());
currentDate.setDate(currentDate.getDate()+1);
//Output is 05/22/2013
console.log(currentDate);


Thanks,
Imdadhusen
 
Share this answer
 
v2
Comments
sunil mali 20-May-13 9:41am    
I want to add 1 day, not in currrent date, i want to add it in date which is in one of my textbox.
You can do this:

JavaScript
var someDate = new Date($('#textboxID').val());
someDate.setDate(someDate.getDate() + 1); 
$('#someOtherTextboxID').val(someDate);


You could also extend the javascript Date object like this

JavaScript
Date.prototype.addDays = function(days) {
    this.setDate(this.getDate() + days);
    return this;
};


and the call it like this:

JavaScript
var someDate = new Date($('#textboxID').val());
someDate.addDays(1);
$('#someOtherTextboxID').val(someDate);
 
Share this answer
 
v2
Modify below code according to your needs.But the basic idea is as follows:

DateTime dt = convert your desired date to datetime here;
dt = dt.AddDays(days to add);
Console.WriteLine(dt.ToString());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900