0 votes
1 view
in SQL by (36k points)

Can anyone explain how to format the date in SQL Server?

1 Answer

0 votes
by (86.8k points)

FORMAT () function is used to format the date in SQL. It is similar to CONVERT() function but with more date formats and has more flexibility than CONVERT().

Here are the few examples using FORMAT() and the output:

SELECT FORMAT (getdate(), 'dd/MM/yyyy ') as date                        -  06/05/2020

 

SELECT FORMAT (getdate(), 'dd/MM/yyyy, hh:mm:ss ') as date  -  21/03/2018, 11:36:14

 

SELECT FORMAT (getdate(), 'dddd, MMMM, yyyy') as date          - Wednesday, May, 2020

 

SELECT FORMAT (getdate(), 'MMM dd yyyy') as date                      - May 06 2020

 

SELECT FORMAT (getdate(), 'hh:mm:ss tt') as date                          - 06:05:14 AM

If you want to take a course that can provide Instructor-led training and certification then register in this SQL Certification program by Intellipaat.

Related questions

0 votes
1 answer
asked Apr 26 in SQL by Sudhir_1997 (36k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...