Click here to Skip to main content
11,430,829 members (76,959 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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
Comments
OriginalGriff at 16-Nov-12 4:59am
   
And which part is giving you a problem?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 .

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


Regards
Dominic
  Permalink  
v2
Rate this: bad
good
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.

Milind
  Permalink  
Rate this: bad
good
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[^]
  Permalink  
Comments
Milind Thakkar at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2015
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