SQL Server Code Example

Using the Format Function with a Date

A practical SQL Server date and time example for Using the Format Function with a Date.

Example and Notes

Use this SQL Server example as a starting point for development, troubleshooting, reporting, or maintenance work. Review it against your schema, data volume, permissions, and SQL Server version before using it in production.

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

Production Review

WSI can adapt this script for your database, improve error handling, tune performance, document the logic, and help deploy it safely.

Readable Example

The original sample is preserved and presented in a cleaner professional layout.

Practical Context

Each example is framed around how it may be used in real SQL Server work.

Expert Support

WSI can adapt examples for your specific schema, business rules, and performance needs.

About Us

WSI is a small business and a leading provider of custom SQL Server/Azure programming and database solutions for government entities, Fortune 1000 companies, and emerging businesses. We are your custom SQL Server/Azure development experts.

Privacy Notice

We use essential cookies to make this site work. With your permission, we may also use analytics or marketing cookies.