I have a table named a125 in my DB postgresql that looks like that :
| objectid | statut | date_debut (timestamp without time zone) |
|---|---|---|
| 52138 | validé | 2022-01-18 23:00:00 |
| 52139 | instruction | 2022-01-23 23:00:00 |
| 52140 | instruction | 2022-01-24 23:00:00 |
| 52141 | instruction | 2022-01-26 23:00:00 |
| 52142 | pre-instruction | 2022-01-27 23:00:00 |
| 52143 | validé | 2022-01-30 23:00:00 |
My goal is to get the value (date and time) that equals 2 days before any date in my table in order to compare it with my date_debut column when the current date equals 2 days before any date, I tried to use :
SELECT CURRENT_DATE integer '2'
--output : 2022-01-13
But the output of that gives me just the current date 2 days without any time specification;
My question is : How can I calculate a value that returns the exact time and date 2 days before any date stored in my date_debut column?
CodePudding user response:
Use the interval operator, like so,
select date_debut interval '-2 days' from tbl_a125
CodePudding user response:
If you want to get the specific Timestamps 2 days before the dates in your "date_debut" Column you should use:
SELECT date_debut - INTERVAL '2 DAY' FROM a125;
