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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:45+00:00 2026-05-28T21:31:45+00:00

I have a minor issue in handling DateTime in C#. I have designed a

  • 0

I have a minor issue in handling DateTime in C#. I have designed a windows application that interacts with Harris automation system. The application receives all triggers for EPG programs. Now I have this issue:

trigger received DateTime : 2012-01-31 23:58:23

trigger exact time : 00:03:53 ( this value can be either > now() or < now()

Here is the code that handles this:

DateTime segmentStartDateTime = DateTime.Now.ToUniversalTime().Date;
segmentStartDateTime = segmentStartDateTime +  item.TIME;

If we test this code with the case above, I get segmentStartDateTime = 2012-01-31 00:03:53, which is the wrong value (the right value should be 2012-02-01 00:03:53).

I am sure one of you have faced this issue before and I’ll appreciate any help to fix this (to determine either the time is in the current day or in the day after).


A few more examples:

1)

Input : – Current Time : 2012-03-08 13:27:00 – Received TimeSpan as string : 13:28:30

Output – The program will start at: 2012-03-08 13:28:30

2)

Input : – Current Time : 2012-03-08 23:58:19 – Received TimeSpan as string : 00:02:15

Output – The program will start at: 2012-03-09 00:02:15 (day after)

3)

Input : – Current Time : 2012-03-08 23:58:19 – Received TimeSpan as string : 23:57:43

Output – The program will start at: Now, it’s already time (2012-03-08 23:57:43)

  • 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-28T21:31:45+00:00Added an answer on May 28, 2026 at 9:31 pm
    DateTime NextTimeOfDayAfter(TimeSpan timeOfDay, DateTime start)
    {
      DateTime result = start.Date + timeOfDay;
      if(result<start)
        result=result.AddDays(1);
      return result;
    }
    

    Not sure how this interacts with DST. But IMO DateTime shouldn’t be used for local times anyways.


    Just tested, and both your examples work with my code:

    var now1=DateTime.Parse("2012-03-08 13:27:00");
    var time1=TimeSpan.Parse("13:28:30");
    NextTimeOfDayAfter(time1,now1).Dump();//08.03.2012 13:28:30
    
    var now2=DateTime.Parse("2012-03-08 23:58:19");
    var time2=TimeSpan.Parse("0:02:15");
    NextTimeOfDayAfter(time2,now2).Dump();//09.03.2012 00:02:15
    

    DateTime NextTimeOfDayAfter(TimeSpan timeOfDay, DateTime start, TimeSpan gracePeriod)
    {
      DateTime result = start.Date + timeOfDay;
      if(result+gracePeriod<start)
        result=result.AddDays(1);
      return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a minor mode. If that mode is active and the user hits
In our application we sometimes have to make minor GUI modifications for different customers:
I have a custom control that needs a minor adjustment when running on XP
Hey, SO, minor issue: I have an NSWindow I am using to report exceptions
Exception handling in php ... I have noticed some quirks that seem to make
I have a minor issue with displaying TextViews in my app while running on
I have a minor issue getting my user agent detection to work. Whenever i
I was facing with one minor issue, and I'm wondering: Why? here we have
I have an iPhone app that is using CoreData. I recently made some minor
I have made a minor change to an Excel macro, and although it worked

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.