0

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.?

Salman A
  • 262,204
  • 82
  • 430
  • 521
Sanjiv
  • 980
  • 2
  • 11
  • 29

3 Answers3

2

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.

Salman A
  • 262,204
  • 82
  • 430
  • 521
1

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

Demo

We convert to varchar(16) explicitly so that only the hour and minute components are retained.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

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

Vlam
  • 1,622
  • 1
  • 8
  • 17