DateInterval Typecasting?

Hi - Starting to get my feet wet, and I believe I am mixing-up concepts but…

When running the code below, I receive a type mismatch exception on the ListBox - I’ve tried declaring Duration as Integer and then typecasting the subtraction to no avail. I can see I do get the correct value for Duration in the debugger.

Var StartDate As New DateTime(DeliverableStartDatePicker.SelectedDate)
Var EndDate As New DateTime(DeliverableEndDatePicker.SelectedDate)
Var Duration As New DateInterval

Duration = (EndDate - StartDate)

Is there a good way to “extract” the value from Duration?


Duration is a DateInterval; you’ll have to access one (or more) of its attributes:, e.g. ListBox1.AddRow(CStr(Duration.Days))

Note that, if you want just days, you’ll have to convert the years and months in the interval to days and sum them with the given days, which may be tricky. It may actually be easier to take the original dates, subtract the SecondsFrom1970 attributes, and then convert seconds to days.

Var DurationInDays as Double
DurationInDays = (EndDate.SecondsFrom1970-StartDate.SecondsFrom1970)/86400

Thanks Matthew!