Calculate difference between two dates but only for working hours (VB.NET)

Hi Experts,

I'm trying to think of a way in vb.net to get the difference between a start date and an end date.

But the difference has to take into consideration working hours...i.e. only calculate the difference between 9am and 5pm.

I've hit a writers block on this one...
LVL 2
samroseAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
You can try something like this and you can change TotalHours to TotalMinutes or less for higher precision.

        Dim dt1 As New DateTime(2009, 5, 17, 9, 10, 0)
        Dim dt2 As DateTime = Now
 
        If dt2.Subtract(dt1).TotalHours > 0 Then
            Stop ' Date 2 greather then 1
        End If

Open in new window

0
 
danirk2Commented:
to make it more complicate, what about working days(!) ? Can the dates span weekend?
0
 
samroseAuthor Commented:
yeah different times at weekends :)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
danirk2Connect With a Mentor Commented:
Now I've hit a writers block on this one...
0
 
cdaly33Connect With a Mentor Commented:
I'm not exactly sure how it would all paste together but I think the first step is to get away from date objects.  I'd think if you covert it to ticks or milliseconds then you could figure the total milliseconds then convert back in to minutes or hours and minutes later.
0
 
samroseAuthor Commented:
Took a while but I completed the routine thanks to all ....
0
All Courses

From novice to tech pro — start learning today.