Posts

Showing posts from July, 2021

How to get different date formats in SQL Server

Image
  How to get different date formats in SQL Server Use the SELECT statement with CONVERT function and date format option for the date values needed To get YYYY-MM-DD use this T-SQL syntax SELECT CONVERT(varchar, getdate(), 23) To get MM/DD/YY use this T-SQL syntax SELECT CONVERT(varchar, getdate(), 1) Check out the chart to get a list of all format options Below is a list of SQL date formats and an example of the output.  The date used for all of these examples is "2006-12-30 00:38:54.840". DATE ONLY FORMATS Format # Query Format Sample 1 select convert(varchar, getdate(), 1) mm/dd/yy 12/30/06 2 select convert(varchar, getdate(), 2) yy.mm.dd 06.12.30 3 select convert(varchar, getdate(), 3) dd/mm/yy 30/12/06 4 select convert(varchar, getdate(), 4) dd.mm.yy 30.12.06 5 select convert(varchar, getdate(), 5) dd-mm-yy 30-12-06 6 select convert(varchar, getdate(), 6) dd-Mon-yy 30 Dec 06 7 select convert(varchar, getdate(), 7) Mon dd, yy Dec 30, 06 10 select convert(varchar, getdate()...