### Calculate Days beween Dates

This sub calculates the number of days between two given dates.
'Calculate the number of days beween two dates
'Parameter:
'StartDate in format MM/dd/YYYY
'EndDate in format MM/dd/YYYY
'Returns daysbetween as Int
'Examples:
'Dim daystillyearend As Int = DaysBetweenTwoDates("05/14/2015","12/31/2015")
`Sub DaysBetweenTwoDates(D1 As String, D2 As String) As Int
Dim startdate, enddate, t As Long
startdate = DateTime.DateParse(D1)
enddate = DateTime.DateParse(D2)
Dim daysbetween As Int
t = enddate - startdate
Log(t)
't = Abs(enddate - startdate)
daysbetween = Floor(t / DateTime.TicksPerDay)
Return daysbetween
End Sub`
Example Usage
Dim startdate As String = DateTime.Date(DateTime.Now)
Dim enddate As String = "12/31/" & DateTime.GetYear(DateTime.Now)
Dim daystillyearend As Int = DaysBetweenTwoDates(startdate, enddate)
Dim sb As StringBuilder
sb.Initialize
sb.Append("Days till Year End").Append(CRLF)
sb.Append("Start Date: ").Append(startdate).Append(CRLF).Append("End Date: ").Append(enddate).Append(CRLF)
sb.Append(daystillyearend).Append(" days")
Log(sb.ToString)

Changed: , Category: DateTime, File: T6C183M1318.htm, ID: 1318