Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

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

Posted on 2009-05-17
Medium Priority
673 Views
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...
0
Question by:samrose
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 5

Expert Comment

ID: 24407457
to make it more complicate, what about working days(!) ? Can the dates span weekend?
0

LVL 2

Author Comment

ID: 24407463
yeah different times at weekends :)
0

LVL 5

Assisted Solution

danirk2 earned 600 total points
ID: 24407483
Now I've hit a writers block on this one...
0

LVL 9

Assisted Solution

cdaly33 earned 600 total points
ID: 24407521
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

LVL 48

Accepted Solution

jpaulino earned 800 total points
ID: 24407538
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
``````
0

LVL 2

Author Comment

ID: 24802856
Took a while but I completed the routine thanks to all ....
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month11 days, 3 hours left to enroll