how to increment a date and time they are split in to fields

Posted on 2011-10-19
Last Modified: 2012-05-12

I need to do a sweep of a database and increment the start date time by x amount of hours. the hours to increment is derived in an earlier statement. basically i have two fields

START_DATE datetime
START_TIME datetime

I guess i need to cast them into a single field, increment it by the increment value and write it back, I would liked to achieve this in a single statement. Can anyone suggest how this statement might look?

Thanks in advance

Question by:Michael
    LVL 4

    Expert Comment

    LVL 22

    Accepted Solution



    declare @START_DATE datetime
    declare @START_TIME datetime

    set @START_DATE='2011-11-01'
    set @START_TIME='20:00:00'

    select CONVERT(datetime, CONVERT(varchar, DATEADD(hh, 10, @START_DATE+@START_TIME), 101)) as START_DATE,
    CONVERT(datetime, CONVERT(varchar, DATEADD(hh, 10, @START_DATE+@START_TIME), 114)) as START_TIME


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now