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 more difficult than I thought it would be. How do I approach this?
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 more difficult than I thought it would be. How do I approach this?
4条答案
按热度按时间yrdbyhpb1#
SQL Server 2012+
SQL Server 2008/2008 R2:
SQL Server 2000 / 2005:
8nuwlpux2#
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:returns (when run on 11th Jan 2018):
nr9pn0ug3#
You can construct this as you like with day, hour, minute etc.
7d7tgy0s4#
specified_date - Output Column name
20:00 - Specified time(24 hr Format -Default)
getdate() - To get Today's date.