skip to Main Content

I have the following query which I’m unable to solve:

SELECT DISTINCT
    m.id,
    TO_CHAR(m.date, 'YYYY-MM-DD')::timestamp AS formatted_date,
FROM table.match m

In the formatted_date field I get the following output:

2012-12-02T00:00:00.000Z

Does anyone know how to format it as to get just 2012-12-02?

The version I’m using is: PostgreSQL 13.10

Thank you all for any help!

2

Answers


  1. to get just 2012-12-02 :

    SELECT 
       m.id,
       to_char(m.date, 'YYYY-MM-DD') as formatted_date
    FROM table.match m
    

    to remove time nut still have datetime datatype use date_trunc

    SELECT DISTINCT
        m.id,
        date_trunc('day', m.date)::date AS formatted_date
    FROM table.match m
    
    Login or Signup to reply.
  2. If you are going for the 2012-12-02 output, simply cast m.date to date type

    SELECT DISTINCT
        m.id,
        m.date::DATE AS formatted_date
    FROM table.match m;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search