Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

how to auto calculate days that key in by user.i want it to auto calculate whenever they just select the date from ajax calendar extender.

the program is actually allow user key in their task which is given by boss.there are textbox which receive start date, due date. the diff is between current date and due date.so if the diff days is greater than due date then i will display indicator in red color.if the diff date is still in period task, then the indicator will show green color.


thanks in advance
musiw.
Posted
Updated 8-Jul-12 19:05pm
v2

1 solution

How do you expect that to work?
Diff = end - start
if (diff > end) RED


Since you are using the end data to calculate the difference, there is no point in comparing it to the end date because it cannot be anything other than on the end date...
 
Share this answer
 
Comments
musiw 9-Jul-12 2:02am    
i dont know how to code it.lets say if i want to know the diff between start date and due date.how to code it?especially when im using ajax calendar extender.
OriginalGriff 9-Jul-12 2:13am    
Depends on where you are calculating it. Your question title says "C#" so I'll give you that:

DateTime endDate = DateTime.Parse(textboxEndDate.Text);
DateTime startDate = DateTime.Parse(textboxStartDate.Text);
TimeSpan diff = endDate - startDate;
double daysBetween = diff.TotalDays;
musiw 9-Jul-12 3:45am    
ok.i already try your code.but it calculate wrong answer. let say i pick from 7/4/2012 end 7/10/2012 it become 183. i just want diff on days not month and year.
OriginalGriff 9-Jul-12 4:01am    
Ah. That's not the fault of the code - it's an internationalization problem. There are 183 days between 7th April 2012 and 7th October 2012. I suspect you need to use the Calender.SelectedDate property instead...
musiw 9-Jul-12 4:22am    
DateTime endDate = DateTime.Parse(TextBox4_CalendarExtender.SelectedDate.ToString());
DateTime startDate = DateTime.Parse(TextBox3_CalendarExtender.SelectedDate.ToString());
TimeSpan diff = endDate - startDate;
double daysBetween = diff.TotalDays;
Label13.Text = daysBetween.ToString();

error appear - >> String was not recognized as a valid DateTime.

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