Zeno
Zeno

Reputation: 1839

TSQL: format date with date & hour?

In TSQL, I have a datetime variable that I want to display/group by:

YYYY-MM-DD HH

CONVERT() seems to be able to pull out date formats, but only predefined ones and not something like MySQL's DATE_FORMAT which allows me to customize the format.

What function in TSQL lets me customize the date format?

Upvotes: 1

Views: 1103

Answers (2)

jhenderson2099
jhenderson2099

Reputation: 964

Are you using SQL Server 2012 or later? If so you should be able to use the built-in FORMAT function.

Upvotes: 0

Kaf
Kaf

Reputation: 33839

Try this (replace Getdate() function with your column name):

SELECT CONVERT(VARCHAR(13), GETDATE(), 120)

Upvotes: 1

Related Questions