Solved

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

Posted on 2009-05-17
6
669 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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