Date in mmm yyyy format in postgresql

SqlPostgresql

Sql Problem Overview


I have a table with a column of type timestamp without time zone.

I want to select that column with the mmm yyyy format – for example, “Mar 2011”. How to format it that way? I tried:

select cast(now() as date)

but it is giving me the incorrect format.

Sql Solutions


Solution 1 - Sql

SELECT TO_CHAR(NOW(), 'Mon YYYY');

Solution 2 - Sql

> DateAndTime Reformat:

SELECT *, to_char( last_update, 'DD-MON-YYYY') as re_format from actor;

> DEMO:

enter image description here

Solution 3 - Sql

You need to use a date formatting function for example to_char http://www.postgresql.org/docs/current/static/functions-formatting.html

Solution 4 - Sql

I think in Postgres you can play with formats for example if you want dd/mm/yyyy

TO_CHAR(submit_time, 'DD/MM/YYYY') as submit_date

Solution 5 - Sql

You can write your select query as,

select * from table_name where to_char(date_time_column, 'YYYY-MM')  = '2011-03';

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDeepak KumarView Question on Stackoverflow
Solution 1 - SqlMohamed SalighView Answer on Stackoverflow
Solution 2 - SqlRam PukarView Answer on Stackoverflow
Solution 3 - SqlYavor ShahpasovView Answer on Stackoverflow
Solution 4 - SqlElmira BehzadView Answer on Stackoverflow
Solution 5 - SqlRohit SonawaneView Answer on Stackoverflow