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

Hi Experts,

I'm trying to think of a way in 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...
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

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

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

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...
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.
samroseAuthor Commented:
Took a while but I completed the routine thanks to all ....
All Courses

From novice to tech pro — start learning today.