Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 995129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:40:29+00:00 2026-05-16T06:40:29+00:00

I need to calculate in hours how much time has elapsed from when a

  • 0

I need to calculate in hours how much time has elapsed from when a record was created to the current time. The hard part is I need to exclude weekend times from this.

I have been working on this for quite a while and I am just lost. Here is what I have so far. Thank you in advance for your help.

   Dim MyStartTime As DateTime = "2010-08-09 07:00:00.000"
    Dim MyEndTime As DateTime = DateAdd("h", -1, Now())

    Dim MyHours As Integer = 0

    If Weekday(MyStartTime) > 1 And Weekday(MyStartTime) < 6 Then

        MyHours = DateDiff("h", MyStartTime, MyEndTime)

    ElseIf Weekday(MyStartTime) = 6 Then
        Dim EndTime
        date1.Date()
        MyHours = DateDiff("h", MyStartTime, MyEndTime)


    End If

    lblHours1.Text = MyHours

What algorithm in VB.NET would best suit this calculation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:40:30+00:00Added an answer on May 16, 2026 at 6:40 am

    Here’s one method:

    Determine the TimeSpan in hours for the entire range.

    Determine if the start and end falls on a weekend. Subtract the appropriate hours. If starting on a weekend, remove the hours until Monday at 00:00. If ending on a weekend, subtract hours elapsed since Saturday at 00:00. Then account for any full weekend days falling in between.

    This requires implementing 3 methods to return a number of hours to be subtracted. If none, just return 0 on each:

    NumberOfHoursBetweenDateAndNextMonday – when starting on a weekend day.
    NumberOfHoursBetweenDateAndEarliestSaturday – when ending on a weekend day.
    NumberOfFullWeekendHoursWithinRange – all those days in between.

    Dim MyHours As TimeSpan = MyEndTime - MyStartTime
    
    'account for start being on a weekend
    If (MyStartTime.DayOfWeek = vbSaturday Or vbSunday) Then
        'subtract number of hours until Monday at 00:00
        MyHours -= NumberOfHoursBetweenDateAndNextMonday(MyStartTime)
    
    End If
    
    If (MyEndTimeTime.DayOfWeek = vbSaturday Or vbSunday) Then
       'subtract number of hours elapsed after Saturday at 00:00
       MyHours -= NumberOfHoursBetweenDateAndEarliestSaturday(MyEndTime)
    End If
    
    MyHours -= NumberOfFullWeekendHoursWithinRange(MyStartTime, MyEndTime)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate Math.exp() from java very frequently, is it possible to get
I need to calculate the time complexity of the following code: for (i =
I am building a quiz and i need to calculate the total time taken
I need to calculate the DateDiff (hours) between two dates, but only during business-hours
I need to calculate the quantity of nights (stay at a hotel) from the
I need to calculate the time taken to execute each thread. So I used
I need to calculate from pricing based on some business rules and I do
I need to calculate changes off of time series of nullable numbers. The following
I need to calculate averages, standard deviations, medians etc for a bunch of numerical
I have two system calls GetSystemTime() and GetThreadTimes() that I need to calculate the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.