timespan - VB.net Get total time between two time spans -
i wondering if there function vb.net can tell me total time 2 different time spans have in common.
for example, have these 2 different time spans:
1st date : (2013-01-01 8:30 am) - (2013-01-01 11:30pm) 2nd date : (2013-01-01 10:00 pm) - (2013-01-02 6:00 am)
can vb.net tell me answer 1 hour , 30 mins? (perhaps in decimal) 1 hour , 30 minutes because 10:00pm in evening , 11:30 in evening falls in other time span.
summary:
i need function tell me how many hours in timespan part of night shift. (that's 10:00 pm 6:00 am).
date1 , date2 represents first time span , date2 , date3 represent second time span. if order of dates changed have define analogous else first if.
dim date1 date = #1/1/2013 8:30:00 am# dim date2 date = #1/1/2013 11:30:00 pm# dim date3 date = #1/1/2013 10:00:00 pm# dim date4 date = #1/2/2013 6:00:00 am# dim timeperiod timespan if date3.date >= date1.date , date3.date <= date2.date if date4.date <= date2.date timeperiod = date4.timeofday - date3.timeofday else timeperiod = date2.timeofday - date3.timeofday end if end if msgbox(timeperiod.tostring)
edit: timeperiod = date4- date3
convert difference timespan
edit 2:the code above have returned date2-date3 if there there no common time span. code below return 0 in such case. when comparing 2 date
variables in if
statement, timeofday
part neglected.
dim date1 date = #1/1/2013 8:30:00 am# dim date2 date = #1/1/2013 11:30:00 pm# dim date3 date = #1/1/2013 10:00:00 pm# dim date4 date = #1/2/2013 6:00:00 am# dim timeperiod timespan if date3 >= date1 , date3 <= date2 if date4 <= date2 timeperiod = date4 - date3 elseif date3 < date2 timeperiod = date2 - date3 elseif date3.date = date2.date if date3.timeofday < date2.timeofday timeperiod = date2 - date3 else timeperiod = timespan.fromdays(0) end if else timeperiod = timespan.fromdays(0) end if end if msgbox(timeperiod.tostring)
Comments
Post a Comment