Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Object:calculating the diff between the two dates? 1

Status
Not open for further replies.

user2

Technical User
Aug 10, 2001
70
US
I have a form to calculate dates of stay and charges.My form has 2 calendars for arrival and departure. How can I hold the dates and use them to get the Interval of days?
Thanks in advance
 
Clarification. It is the DateTime Structure and if you want Calendar days rather than duration then you need to use the Date property of the DateTime Structure.
Ex.
' Calendar Days
Dim dte1 As New DateTime(2004, 1, 1, 23, 59, 0)
Dim dte2 As New DateTime(2004, 1, 2, 0, 0, 0)
Dim dys As Integer = dte2.Date.Subtract(dte1.Date).Days
' dys = 1

' Duration
Dim dte1 As New DateTime(2004, 1, 1, 23, 59, 0)
Dim dte2 As New DateTime(2004, 1, 2, 0, 0, 0)
Dim dys As Integer = dte2.Date(dte1).Days
' dys = 0


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Thank you all fro your help. If I want to ignore the time, leap years, holidays .Is there a simple way to do that?
Thanks

 
The subtract method (or "-" operator) will automatically take leap years into account, but it doesn't know anything about holidays because they're local in nature (Here in the US, we don't celebrate Australia Day, for example).

You would have to do that yourself. Convert the results of the subtraction operation to a DateTime, then call the AddDays method with a negative value to subtract the needed number of holidays.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top