Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

extract only date from current_date + interval data type in postgres

I am trying to get only date without time in postgres from the following statement:

select current_date - date_trunc('day',interval '1 month');

But returns me that:

2023-02-07 00:00:00

What could be going wrong here. I see that date_trunc function returns timestamp and intervals cannot be cast to date type:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select current_date - interval '1 month'::date;

>Solution :

You should be able to place the interval expression into a closure, and then cast that:

select (current_date - interval '1 month')::date;  -- 2023-02-07
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading