none
Adding seconds in datetime field

    Question

  • Hi, I have column-doac in proc table but I want to update the date to reflect the time. How I can update using the function and get the desired output. Help pl.

    Select * from prod

    DOAC

    --------

    2012-09-29 00:00:00.000  (Currently this date is in the system)

    2012-09-29 15:30:00.000 (This is desired output. I want to update the time 15:30 in this date)

    Thanks.



    • Edited by Kenny_Gua Tuesday, November 20, 2012 6:01 PM
    Tuesday, November 20, 2012 6:00 PM

Answers

  • try :

    declare @date datetime , @time time

    set @date = '2012-09-29 00:00:00.000'
    set @time = '15:30'
    select convert(datetime,@date + @time)

    As olaf mentioned , you can use dateadd function.
    • Edited by JR1811 Tuesday, November 20, 2012 6:13 PM
    • Marked as answer by Kenny_Gua Tuesday, November 20, 2012 6:37 PM
    Tuesday, November 20, 2012 6:04 PM

All replies

  • try :

    declare @date datetime , @time time

    set @date = '2012-09-29 00:00:00.000'
    set @time = '15:30'
    select convert(datetime,@date + @time)

    As olaf mentioned , you can use dateadd function.
    • Edited by JR1811 Tuesday, November 20, 2012 6:13 PM
    • Marked as answer by Kenny_Gua Tuesday, November 20, 2012 6:37 PM
    Tuesday, November 20, 2012 6:04 PM
  • Hello Kenny,

    You can use the DATEADD function to add hour/minute/seconds to a date value.


    Olaf Helper

    Blog Xing

    • Proposed as answer by JR1811 Tuesday, November 20, 2012 6:44 PM
    Tuesday, November 20, 2012 6:05 PM
  • --You can pass your time in minutes as integer to dateadd function:
    
    SELECT DATEADD(minute,930,'2012-09-29 00:00:00.000') 
    

    Tuesday, November 20, 2012 6:08 PM
    Moderator