Construct DateTime using today's date at a specific time

后端 未结 4 1419
春和景丽
春和景丽 2020-12-31 15:43

I\'d like to get 4:30 PM of the current day. Hard-coding this way doesn\'t work:

SELECT \'07242012 16:30:00.000\'

This is proving to be mor

4条回答
  •  遥遥无期
    2020-12-31 16:24

    Probably the easiest thing to do is to cast the current date/time to a date (stripping the time off), cast it back to a datetime to allow use of datetime's overloaded + (plus) and, finally cast your desired textual time to a datetime. As follows:

    select cast(cast(sysutcdatetime() as date) as datetime) + cast('16:30' as datetime)
    

    returns (when run on 11th Jan 2018):

    2018-01-11 16:30:00.000
    

提交回复
热议问题