Sql Tutorial Class


Date format in SQL

Date Format in SQL.


Some time user need to display the data in different format. For this propose user can change the date format in SQL. The CONVERT keyword is used to change the date base on date format number.

How to change date format in SQL.

Syntax:

SELECT CONVERT (data_type DATE, date_format_number)

Example:

SELECT CONVERT (Varchar GETDATE(), 1) 

Result will be
MM/dd/yy
Format

SQL Commands on DATE FORMATS
select convert(varchar, getdate(), 1) --MM/dd/yy
select convert(varchar, getdate(), 2) --yy.MM.dd
select convert(varchar, getdate(), 3) --dd/MM/yy
select convert(varchar, getdate(), 4) --dd.MM.yy
select convert(varchar, getdate(), 5) --dd-MM-yy
select convert(varchar, getdate(), 6) --dd MM yy
select convert(varchar, getdate(), 7) --MM dd,yy
select convert(varchar, getdate(), 10) --MM-dd-yy
select convert(varchar, getdate(), 11) --yy/MM/dd
select convert(varchar, getdate(), 12) --yyMMdd
select convert(varchar, getdate(), 23) --yyyy-MM-dd
select convert(varchar, getdate(), 101) --MM/dd/yyyy
select convert(varchar, getdate(), 102) --yyyy.MM.dd
select convert(varchar, getdate(), 103) --dd/MM/yyyy
select convert(varchar, getdate(), 104) --dd.MM.yyyy
select convert(varchar, getdate(), 105) --dd-MM-yyyy
select convert(varchar, getdate(), 106) --dd MM yyyy
select convert(varchar, getdate(), 107) --MM dd,yyyy
select convert(varchar, getdate(), 110) --MM-dd-yyyy
select convert(varchar, getdate(), 111) --yyyy/MM/dd
select convert(varchar, getdate(), 112) --yyyyMMdd


No comments:

Post a Comment