Home > Mobile >  Display a day of week in text in postgresql
Display a day of week in text in postgresql

Time:01-18

This query displays count Actions grouped by day of the week.

select count(*) c, 
date_part('dow', "updatedAt"  at time zone 'Europe/Paris') dow
from "Action" date_part('dow', "updatedAt"  at time zone 'Europe/Paris')

Days are displayed as number. Is there a way to display it as text? Does PostgreSQL has such a function?

CodePudding user response:

IF you want text format use ::TEXT at the end. in future you can use other like ::DATE, ::TIMESTAMP, ::DECIMAL...

date_part('dow', "updatedAt" at time zone 'Europe/Paris')::TEXT dow

CodePudding user response:

Use to_char() to format a date or timestamp value as text. You can use Day to display the day's name (e.g. Tuesday)

select count(*) c, 
       to_char("updatedAt"  at time zone 'Europe/Paris', 'Day') dow
from "Action" 
group by to_char("updatedAt"  at time zone 'Europe/Paris', 'Day')
  • Related