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

Postgresql WHERE statement when date and time are in the same column

SELECT
scheduling_appointment.scheduling_datetime
FROM
scheduling_appointment

I need to include a WHERE statement to pull only dates within the last week, but the date and time are in the same column:

2020-12-01 09:30:00-06
2022-09-12 08:00:00-06
2021-02-22 10:30:00-06

How can I do this? I don’t think a LIKE statement would work.

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

>Solution :

Assuming your scheduling_datetime column is of type timestamp, you can query like below,

SELECT * from tblname WHERE
scheduling_datetime between now() + '-1 week'::interval and now()

This will return you the records where the date part of your column is falling within last week.

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