Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 textboxes namely
1.)Start Date
2.)End Date
3.)No of Leaves
when i select the start date and end date it should automatically calculate the no of days and display it in the no.of leaves textbox and to be stored in the database.
the no of leaves textbox should be readonly.
so,plz help me out .
Posted
Comments
OriginalGriff 16-Nov-12 4:59am    
And which part is giving you a problem?

Hi
Instead of text boxes, it is better to use DateTimePicker control. So the calculations will be easier.

You can use the below code find the difference in dates .

C#
TimeSpan dtDiff =   dtEnd.Value.Subtract(dtStart.Value);
         int iDiffValue  = dtDiff.Days;



Regards
Dominic
 
Share this answer
 
v2
You can use DateTime.Compare method as shown below

C#
NumLeaves.Text = DateTime.Compare(date1, date2).ToString();

Here NumLeaves is your textbox showing number of leaves

Hope that helps. If it does, mark it as answer/upvote.

Milind
 
Share this answer
 
Are you calculating the amount of leave an employee is taking? If so, you should probably only count the business days. Have a look at this StackOverflow answer[^]
 
Share this answer
 
Comments
MT_ 16-Nov-12 7:00am    
Good point :-) my +5

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