Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-17
6
Medium Priority
?
676 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 600 total points
ID: 24407483
Now I've hit a writers block on this one...
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 9

Assisted Solution

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

by:
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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

971 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