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
  • 248,760
  • 80
  • 417
  • 510
Sanjiv
  • 620
  • 2
  • 8
  • 28

3 Answers3

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
  • 451,927
  • 24
  • 239
  • 318
1

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
  • 248,760
  • 80
  • 417
  • 510
0

Use the datepart function which can extract specific parts of the date value.

https://docs.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql?view=sql-server-2017

Vlam
  • 1,464
  • 1
  • 6
  • 15