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

  • SEARCH
  • Home
  • 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 3242112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:16:37+00:00 2026-05-17T18:16:37+00:00

I need a TimeSpan that takes into account working hours. Let’s say that if

  • 0

I need a TimeSpan that takes into account working hours. Let’s say that if we configure the TimeSpan with an 8 hour day, two days should return 16 total hours instead of 48. Does anybody know of such a class?

Thanks.

Edit

I need the same functionality as timespan but with configurable day duration. Adding, subtracting,…, should work taking this into account. I tried to extend TimeSpan, but it’s sealed. Maybe I should go for some extension methods to implement this as Oded suggested (or something similar).

  • 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-17T18:16:38+00:00Added an answer on May 17, 2026 at 6:16 pm

    If you simply want to figure out each day as 8 hours, you can do this:

    return TimeSpan.TotalHours / 3;
    

    Update:

    Now that you provided some more detail, I would suggest wrapping timespan with your own type – you can have an HoursInWorkingDay property in it which will allow you to configure the number of hours in a working day.

    Have a constructor that takes a timespan and assign that to a private timespan that you can use for calculations:

    public class WrappedTimeSpan
    {
        private TimeSpan ts;
        private int hoursInDay = 8;
    
        public WrappedTimeSpan(TimeSpan origTS)
        {
            ts = origTs;
        }
    
        public WrappedTimeSpan(TimeSpan origTS, int hoursInDay) : this(origTs)
        {
            hoursInDay = hoursInDay;
        }
    
        public int HoursInDay { get;}
    
        public int WorkingHours { get { return ts.TotalHours / hoursInDay; }}
    }
    

    This can be extended to cater for any other requirements you have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have user typed times that need parsing into DateTime or TimeSpan (the date
i have code that takes a csharp datetime and converts it into a long
I need a way to create a TimeSpan time picker column, that allow more
Need some regular expressions help. So far I have my code working to allow
Need help with a query that I wrote: I have three tables Company id
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
I take the difference between two DateTime fields, and store it in a TimeSpan
I have a requirement that regardless of the start and dates that I need
It appears that ConfigurationElement of TimeSpan can't handle values larger than 23:59:59. Are there
I am currently developing a system that has need for a session time out

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.