How to add time to DateTime in SQL

后端 未结 9 1991
一生所求
一生所求 2020-12-29 01:47

I\'m trying to add custom time to datetime in SQL Server 2008 R2.

Following is what I\'ve tried.

SELECT DATEADD(hh, 03, DATEADD(mi,         


        
相关标签:
9条回答
  • 2020-12-29 02:08

    Start Day Time : SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), '00:00:00')

    End Day Time : SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), '23:59:59')

    0 讨论(0)
  • 2020-12-29 02:16

    You can do:

    SELECT GETDATE()+'03:30:00'
    
    0 讨论(0)
  • 2020-12-29 02:18

    Try this:

    SELECT  DATEDIFF(dd, 0,GETDATE()) + CONVERT(DATETIME,'03:30:00.000')
    
    0 讨论(0)
  • 2020-12-29 02:23

    For me, this code looks more explicit:

    CAST(@SomeDate AS datetime) + CAST(@SomeTime AS datetime)
    
    0 讨论(0)
  • 2020-12-29 02:26

    Try this

    SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), '03:30:00')
    
    0 讨论(0)
  • 2020-12-29 02:27

    Try this

    SELECT DATEADD(MINUTE,HOW_MANY_MINUTES,TO_WHICH_TIME)
    

    Here MINUTE is constant which indicates er are going to add/subtract minutes from TO_WHICH_TIME specifier. HOW_MANY_MINUTES is the interval by which we need to add minutes, if it is specified negative, time will be subtracted, else would be added to the TO_WHICH_TIME specifier and TO_WHICH_TIME is the original time to which you are adding MINUTE.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题