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 6033141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:26+00:00 2026-05-23T05:26:26+00:00

I need a way to store and manipulate a date range using C# and

  • 0

I need a way to store and manipulate a date range using C# and storing the data in a SQL database. Is storing two DateTimes the best way to go about this?

For example I need to employees to be able to select the duration they spent working on a specific project by selecting the start date and end date using a DatePicker.

I have the following further requirements:

  • I need to support half days at start
    and/or end of the duration.
  • I need to be able to calculate the number of
    days between the two dates (as a
    double where 0.5 is half a day).
  • I need to be able to calculate the
    number of business days between the
    two dates (as a double).
  • The time span needs to be displayed on a
    jquery calendar.
  • The minimum
    duration is half a day.

    A Date Range of 1/2 Day From 24th May to a full day 27th May:
    2011-05-24 12:00:00.000 => 2011-05-28 00:00:00.000

    A Date Range of Full Day From 24th May to a 1/2 day 27th May:
    2011-05-24 00:00:00.000 => 2011-05-27 12:00:00.000

    A Half Day on 24th May:
    2011-05-24 12:00:00.000 => 2011-05-25 00:00:00.000

    A Full Day on 24th May:
    2011-05-24 00:00:00.000 => 2011-05-25 00:00:00.000

Does this representation make sense? Should I rather look at storing a DateTime for the StartDate and a TimeSpan taking into account my requirements?

Edit: also

Does my representation of end date make sense? So that 2nd of may will be saved as ‘2011-05-03 00:00:00.000’ because that is when the duration ends. Bearing this in mind I’ll need to subtract a day from the end date when displaying this in a calendar..

  • 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-23T05:26:27+00:00Added an answer on May 23, 2026 at 5:26 am

    I suggest to save the start and end date to your database. The difference can always be calculated.

    The critical aspect of date ranges is how to handle the boundaries. You can use a mapper for the start/end date to ensure correct time calculations (Inside/Touching):

    // ----------------------------------------------------------------------
    public void TimePeriodMapperSample()
    {
      TimeCalendar timeCalendar = new TimeCalendar();
      CultureInfo ci = CultureInfo.InvariantCulture;
    
      DateTime start = new DateTime( 2011, 3, 1, 13, 0, 0 );
      DateTime end = new DateTime( 2011, 3, 1, 14, 0, 0 );
    
      Console.WriteLine( "Original start: {0}",
                         start.ToString( "HH:mm:ss.fffffff", ci ) );
      // > Original start: 13:00:00.0000000
      Console.WriteLine( "Original end: {0}",
                         end.ToString( "HH:mm:ss.fffffff", ci ) );
      // > Original end: 14:00:00.0000000
    
      Console.WriteLine( "Mapping offset start: {0}", timeCalendar.StartOffset );
      // > Mapping offset start: 00:00:00
      Console.WriteLine( "Mapping offset end: {0}", timeCalendar.EndOffset );
      // > Mapping offset end: -00:00:00.0000001
    
      Console.WriteLine( "Mapped start: {0}",
        timeCalendar.MapStart( start ).ToString( "HH:mm:ss.fffffff", ci ) );
      // > Mapped start: 13:00:00.0000000
      Console.WriteLine( "Mapped end: {0}",
        timeCalendar.MapEnd( end ).ToString( "HH:mm:ss.fffffff", ci ) );
      // > Mapped end: 13:59:59.9999999
    } // TimePeriodMapperSample
    

    Check out the article Time Period Library for .NET (section Calendar Time Periods).

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

Sidebar

Related Questions

What is the best way to store string data across postback. I need to
I need a way to store application-level data (i.e. cross user sessions) in ASP.NET.
I am in need of a lightweight way to store dictionaries of data into
I need a way to store several images in one/two (some projects seems to
What is the best way to maniupulate richtext / *.rtf data in SQL server
What is the best way to store instances of a class to file/database? We
I need some advise on the best way to achive the following: Store a
I need a way to store encrypted data, in a way that I can
I need a way to store large-numbers of variously sized XML data in a
I need a way to store an int for N columns. Basically what I

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.