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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.