Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two text box on which I give two date input by using rapid application development datepicker textbox. I have another text box on which I wanna show the duration of those two text box date.
I want to calculate total days of those to date. Can anyone please provide me a solution?
Posted

Better solution:
TimeSpan ts = secondDate.Value - firstDate.Value;
myTextBox.Text = ts.Days.ToString();

If you just use DateTime.Day, then you will get problems if the month changes, etc.
 
Share this answer
 
Comments
sazib 11-Oct-10 3:54am    
I've got this error after using your solution.
Compiler Error Message: CS1061: 'Telerik.Web.UI.RadDatePicker' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'Telerik.Web.UI.RadDatePicker' could be found (are you missing a using directive or an assembly reference?)

The code is like this-
string user = Session["username"].ToString();
string type = DropDownListType.SelectedValue.ToString();
TimeSpan ts = RadDatePickerStart.Value - RadDatePickerEnd.Value;
durationTextBox.Text = ts.Days.ToString();
Try x = DateTimePicker1.Value.Day - DateTimePicker2.Value.Day.
 
Share this answer
 
Comments
OriginalGriff 10-Oct-10 6:06am    
If you just use DateTime.Day, then you will get problems if the month changes, etc.
Abhinav S 10-Oct-10 6:08am    
Ok makes sense. I can't run this code, but maybe DateTimePicker1.Value.Day - DateTimePicker2.Value and then a simple convertsion to days might also be a solution. Using TimeSpan, however, is the best.
Better Solution is :
Both Days are in Date time Format

System.TimeSpan span = ToDate - DateFrom;
int days = (int)span.TotalDays;
 
Share this answer
 
v2
I want to show the value on the tex tbox after I click on the text box. How do I do that.
 
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