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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:45:13+00:00 2026-06-03T08:45:13+00:00

I have two columns in a table that need to be added together. One

  • 0

I have two columns in a table that need to be added together. One of them is a varchar(4) with military time, minus the colon, including preceding 0s. Another one is an int which describes the duration of an appointment in minutes. Basically I need to add the two together and keep it as a varchar(4), all in the same format as the first column. I’ve used SQL before, but not in any sophisticated manner. What would be the right approach to this? Thanks!

I don’t have to worry about stuff carrying over into the next day.

For example:

time:       '1145'
duration:   45
sum:        '1230'

time:       '0915'
duration:   30
sum:        '0945' (not '945')
  • 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-03T08:45:15+00:00Added an answer on June 3, 2026 at 8:45 am

    The assumption is that the question states the time will always be in 4 digit format hhmm. The query extracts hh and mm from the string and converts into time. The duration in minutes is added to this time value and then converted back to string format hh:mm using the CONVERT function and the colons are removed from the string to get back to the original format.

    Click here to view the demo in SQL Fiddle.

    Script:

    CREATE TABLE timevalues
    (
            timestring  VARCHAR(20) NOT NULL
        ,   duration    INT NOT NULL
    );
    
    INSERT INTO timevalues (timestring, duration) VALUES
        ('1145', 30),
        ('2345', 25),
        ('0815', 125);
    
    SELECT      timestring
            ,   duration
            ,   REPLACE(CONVERT(VARCHAR(5), DATEVALUE, 108), ':', '') AS newtimevalue
    FROM
    (
        SELECT  timestring
            ,   duration
            ,   DATEADD(MINUTE, 
                        duration, 
                        CAST(
                                (   SUBSTRING(timestring, 1, 2) + ':' + 
                                    SUBSTRING(timestring, 3, 2)
                                ) AS DATETIME
                            )
                        ) AS DATEVALUE 
        FROM    timevalues
    ) T1;
    

    Output:

    timestring duration newtimevalue
    ---------- -------- -------------
      1145        30      1215
      2345        25      0010
      0815       125      1020
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has two datetime columns (one for start time and
I have a table that currently has two columns per row and I need
I have two columns in a table that are populated with integer values. For
Suppose I have two columns in a table that represents a graph, the first
Here is the problem: I have two columns in a table that, for each
I have a table that has two columns: CommunityID PersonID And A People table
I have a table that contains common entries in two columns. For Example: Column1
I have a city table that has two columns from_city to_city now lets assume
I have created a table in Visual Studio. That table has two columns. First
I have a table, tblNoComp, that has two columns, both foreign keys pointing to

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.