Click here to Skip to main content
13,259,194 members (50,839 online)
Rate this:
Please Sign up or sign in to vote.
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 15-Nov-12 23:53pm
OriginalGriff 16-Nov-12 4:59am
And which part is giving you a problem?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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 .

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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use DateTime.Compare method as shown below

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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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[^]
Milind Thakkar 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100