Solved

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

Posted on 2009-05-17
6
663 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now