Appearance
DATENAME
Given a datepart, return a character string representation of a specified date, timestamp, or timestamptz.
DATENAME(part, expr)
- part
- See Supported Dateparts.
- expr
- Date, timestamp, or timestamptz containing the specified datepart.
Examples
For example, identify the day of the week a match took place:
premdb=# SELECT matchday, DATENAME('dow', matchday) FROM match LIMIT 5;
matchday | datename
---------------------+----------
2014-05-11 00:00:00 | Sunday
2013-09-21 00:00:00 | Saturday
2013-09-01 00:00:00 | Sunday
2014-04-12 00:00:00 | Saturday
2014-04-26 00:00:00 | Saturday
(5 rows)
DATENAME
is similar to the DATE_PART
function but returns a character string rather than a DOUBLE PRECISION
value. See DATE_PART. Using the previous example, the following compares how DATE_PART
and DATENAME
return the same information but in different formats:
premdb=# SELECT matchday, DATE_PART('dow', matchday), DATENAME('dow', matchday) FROM match LIMIT 5;
matchday | date_part | datename
---------------------+-----------+----------
2014-05-11 00:00:00 | 0 | Sunday
2013-09-21 00:00:00 | 6 | Saturday
2013-09-01 00:00:00 | 0 | Sunday
2014-04-12 00:00:00 | 6 | Saturday
2014-04-26 00:00:00 | 6 | Saturday
(5 rows)