The table below contains the valid format string substitutions that you can use with the strftime()
function in SQLite.
Tag: date format
Valid Time String Formats for SQLite Date/Time Functions
Below is a list of valid time string formats that you can use in any date and time function in SQLite.
Continue readingValid Modifiers for SQLite Date/Time Functions
Below is a list of valid modifiers for date and time functions in SQLite.
Continue readingExtract the Month from a Date in PostgreSQL
In PostgreSQL you can use the EXTRACT()
function to get the month from a date.
You can also use the DATE_PART()
function to do the same thing.
Convert Month Number to Month Name in PostgreSQL
You can use the following code examples in PostgreSQL if you have a month number but you want the month name instead.
Convert Month Name to Month Number in PostgreSQL
In PostgreSQL, if you already have a month name, but you want to convert that name to the month number, you can do this with the EXTRACT()
function.
Get the Month Name from a Date in PostgreSQL
If you’re familiar with PostgreSQL, you might know that you can use the EXTRACT()
and the DATE_PART()
functions to extract the month from a date. But those functions only allow you to extract the month number.
What if you need the month name?
You can get the month name from a date by using the TO_CHAR()
function. This function returns a string based on the timestamp and the template pattern you provide as arguments.
How Language Settings can Affect your FORMAT() Results in SQL Server (T-SQL Examples)
It can be easy to forget that the T-SQL FORMAT()
function provides locale-aware formatting. Locale-aware means that the locale can affect the results. In other words, the exact output you get will depend on the locale.
By default, the function uses the language of the current session to determine the locale. However, this can be overridden by passing a “culture” argument to the function. Doing this allows you to provide results for a particular locale without having to change the language of the current session.
This article contains examples of how locale can affect the results when using the FORMAT()
function in SQL Server.
Custom Numeric Format Strings Supported by FORMAT() in SQL Server
This article provides a reference for the custom numeric format specifiers that can be used when formatting numbers using the FORMAT()
function in SQL Server. Examples included.
What is a Format String in SQL Server?
In SQL Server, the FORMAT()
function enables you to format date/time and number values as a formatted string by passing in a “format string” as the second argument (the first argument is the value that’s being formatted).
Here’s an example of this function in action:
FORMAT(@date, 'dd/MM/yyyy');
In this case the format string is dd/MM/yyyy.
This particular format string specifies that the @date
value should be formatted with a two-digit day, two-digit month, and a four-digit year, in that order, and with forward slashes as the separators.
This would result in something like this:
21/05/2019