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.
Instead, you should use to_char to format the date when you query it, or format it in the client application. Like: SELECT to_char("date", 'DD/MM/YYYY') FROM mytable; e.g.
1) Get the current date To get the current date and time, you use the built-in NOW() function. However, to get the date part only (without the time part), you use the double colons (::) to cast a DATETIME value to a DATE value. The result is in the format: yyyy-mm-dd .
PostgreSQL uses the yyyy-mm-dd format for storing and inserting date values. If you create a table that has a DATE column and you want to use the current date as the default value for the column, you can use the CURRENT_DATE after the DEFAULT keyword.
SELECT TO_CHAR(NOW(), 'Mon YYYY');
DateAndTime Reformat:
SELECT *, to_char( last_update, 'DD-MON-YYYY') as re_format from actor;
DEMO:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With