How to Format the Date & Time in MySQL

In MySQL, the DATE_FORMAT() function allows you to format the date and time.

Here’s an example:

SELECT DATE_FORMAT('2018-12-01', '%W, %d %M %Y');

Result:

Saturday, 01 December 2018

In this example, %W is for the weekday name, %d is for the day of the month, %M is for Month, and %Y is for Year. There are many more format specifiers available that enable you to specify a precise format for dates, as well as the time component.

Continue reading

List of Date Format Specifiers in MySQL

MySQL has a number of functions that allow you to format the date and time. These include functions such as DATE_FORMAT() and TIME_FORMAT().

When using these functions, you provide arguments that tell it what format you’d like the date or time to be in. These arguments are called format specifiers, and they begin with a percentage sign (%) followed by a character (usually a letter, but not always).

The following table lists the format specifiers that can be used when formatting the date and time in MySQL.

Continue reading

How to Format the Date & Time in SQL Server

In SQL Server, you can use the T-SQL FORMAT() function to format the date and/or time. Simply provide two arguments; the date/time and the format to use.

The format is supplied as a format string. A format string defines how the output should be formatted.

TheĀ FORMAT() function also accepts an optional “culture” argument, which allows you to specify a language/locale that the results should adhere to.

Continue reading