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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:20:51+00:00 2026-06-05T02:20:51+00:00

I have this logic in my C# code which gives me time difference between

  • 0

I have this logic in my C# code which gives me time difference between two times

Example inputs are: ’12:00 AM’ – ’11:15 AM’ gives 45 minutes.

DateTime startTime = Convert.ToDateTime(startTimeHH + ":" + startTimeMM + " " + startTimeAMPM);
DateTime endTime = Convert.ToDateTime(endTimeHH + ":" + endTimeMM + " " + endTimeAMPM);
DateTime breakTime = Convert.ToDateTime(breakTimeHH + ":" + breakTimeMM);

TimeSpan hours = endTime.Subtract(startTime);
hours = hours.Subtract(breakTime.TimeOfDay);

I referred some MSDN docs datetime functions in SQL server but couldn’t find these functions which can give me time from input as 12:00 PM

However now I need to move this piece now into SQL server. How do I write it?

Example inputs are: ’12:00 AM’ – ’11:15 AM’ won’t return 45 it will return 75 (it contains 15 as 25)

  • 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-06-05T02:20:52+00:00Added an answer on June 5, 2026 at 2:20 am

    Here is one way to get what looks like a .NET TimeSpan:

    declare @startTimeHH char(2) = '10',
            @startTimeMM char(2) = '30',
            @startTimeAMPM char(2) = 'AM',
            @endTimeHH char(2) = '12',
            @endTimeMM char(2) = '00',
            @endTimeAMPM char(2) = 'PM',
            @breakTimeHH char(2) = '01',
            @breakTimeMM char(2) = '15',
            @startTime DateTime, 
            @endTime DateTime, 
            @breakTime DateTime, 
            @result Time
    
    set @startTime = cast ((@startTimeHH + ':' + @startTimeMM + ' ' + @startTimeAMPM) as Time);
    set @endTime = cast ((@endTimeHH + ':' + @endTimeMM + ' ' + @endTimeAMPM) as Time);
    set @breakTime = cast ((@breakTimeHH + ':' + @breakTimeMM) as Time);
    
    set @result = @endTime - @startTime - @breakTime
    select cast(@result as CHAR(8))
    

    The result is 00:15:00

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

Sidebar

Related Questions

i have this code, and need help with the logic end. I would like
I have a problem with the logic of this code, XNA's Update Method is
Ok, I have this basics PHP logic made for measuring execution time in PHP,
I currently have PHP code that handles the logic for this because I do
I have this div which contents depends of the current time of HTML embedded
I have this horribly stripped delphi code that basically login to server, save cookie
I have this logic in an extension method that creates a paging wrapper: int
I would like to know if I have this SQL logic decoded correctly. Here
I have this piece of logic I would like to implement as a trigger,
I have this requirement of Uploading 1000s of Photos from a window application. Logic

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.