less than 1 minute read

By using the to_char() function with a date or timestamp, we can determine the day of the week by name (e.g. Monday). For instance, to determine what day today is, try a statement like the following:

> select to_char(now(), 'Day');
  to_char
-----------
 Sunday

The Day part of the second argument is just one of many template patterns that can be used for formatting dates and times.

See Data Type Formatting Functions in the Postgres docs for more details.

Via jbranchaud/til.

Tags: ,

Categories:

Updated:

Leave a comment