Date in mmm yyyy format in postgresql
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.
Solution 1:
SELECT TO_CHAR(NOW(), 'Mon YYYY');
Solution 2:
DateAndTime Reformat:
SELECT *, to_char( last_update, 'DD-MON-YYYY') as re_format from actor;
DEMO:
Solution 3:
You need to use a date formatting function for example to_char http://www.postgresql.org/docs/current/static/functions-formatting.html
Solution 4:
You can write your select query as,
select * from table_name where to_char(date_time_column, 'YYYY-MM') = '2011-03';