Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

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

1 Answer

0 votes
by (119k 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, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Dec 30, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked May 7, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer

Browse Categories

...