I have a column in my table (having value- 2017-09-27 15:39:36.000).
I want to select only Date, Hour, Minutes (i.e:- 2017-09-27 15:39) from column.
Can anyone please tell me how to select.?
I have a column in my table (having value- 2017-09-27 15:39:36.000).
I want to select only Date, Hour, Minutes (i.e:- 2017-09-27 15:39) from column.
Can anyone please tell me how to select.?
Use the FORMAT
function to format the date:
SELECT FORMAT(CAST('2017-09-27 15:39:36.000' AS DATETIME), 'yyyy-MM-dd HH:mm')
-- 2017-09-27 15:39
Here is a list of available format specifiers.
One option would be to use CONVERT
with a mask matching the format you want:
SELECT CONVERT(varchar(16), GETDATE(), 120)
2018-09-28 07:58
We convert to varchar(16)
explicitly so that only the hour and minute components are retained.
Use the datepart function which can extract specific parts of the date value.
https://learn.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql?view=sql-server-2017