Microsoft SQL Sample Code
Format Date Function
The Format Date function is a powerful SQL function you can use to manipulate and work with dates. For example, you may want to format a date to display it in a number of various ways. The example scripts below will show you how to format a date for display in your query results. Note - the format function only works in SQL Server 2008 +
Below is a list of formats and an example of the output. The date used for
all of these examples is "2018-11-07 11:36:14.840".
Query |
Sample output |
SELECT FORMAT (getdate(), 'dd/MM/yyyy ') as date |
07/11/2018 |
SELECT FORMAT (getdate(), 'dd/MM/yyyy, hh:mm:ss ') as date |
07/11/2018, 11:36:14 |
SELECT FORMAT (getdate(), 'dddd, MMMM, yyyy') as date |
Wednesday, November, 2018 |
SELECT FORMAT (getdate(), 'MMM dd yyyy') as date |
Nov 07 2018 |
SELECT FORMAT (getdate(), 'MM.dd.yy') as date |
11.07.18 |
SELECT FORMAT (getdate(), 'MM-dd-yy') as date |
11-07-18 |
SELECT FORMAT (getdate(), 'hh:mm:ss tt') as date |
11:36:14 AM |
SELECT FORMAT (getdate(), 'd','us') as date |
11/07/2018 |
If you need any help implementing this
function or modifications made for your needs, please
Click Here to get a free
quote for your Microsoft
SQL Development needs.
Click Here to learn more
about the WSI quoting
process.