Doubt with month and year extraction in PostgreSql data

2

I'm using a select command where I get the month and date year as follows:

extract(year from D.dt_ficha) + extract(month from D.dt_ficha)

But instead of appearing like this: 201711 November 2017, it is adding 2017 + 11 2028 .

How to fix?

    
asked by anonymous 09.11.2017 / 15:33

4 answers

1

I solved it like this:

to_char(D.dt_ficha, 'YYYYMM') as data,
    
09.11.2017 / 17:50
3

Try this:

SELECT  extract(year from D.dt_ficha) || '' || extract(month from D.dt_ficha)
    from D

Where D would be your table;
For me it worked correctly.

    
09.11.2017 / 17:29
0

You can also use the date_trunc function:

date_trunc('month', TIMESTAMP '2001-02-16 20:38:40')

you will get as a result:

2001-02-01 00:00:00
    
12.11.2017 / 21:55
-1

Try using "||"

extract(year from D.dt_ficha) || extract(month from D.dt_ficha)
    
09.11.2017 / 17:01