Solved

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

Posted on 2009-05-17
6
671 Views
Last Modified: 2012-05-07
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
Comment
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
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

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

Author Comment

by:samrose
ID: 24407463
yeah different times at weekends :)
0
 
LVL 5

Assisted Solution

by:danirk2
danirk2 earned 150 total points
ID: 24407483
Now I've hit a writers block on this one...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Assisted Solution

by:cdaly33
cdaly33 earned 150 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

by:
jpaulino earned 200 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

Open in new window

0
 
LVL 2

Author Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nested forach loop to linq 3 43
Format Transaction Number 19 49
Help with viewing image in ReportViewer 14 31
Difference between Highcharts and Mapbox 10 45
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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question