I need to display the current AND last pay periods based on an imported table for biweekly pay dates. The table looks something like this:
2017-03-23 00:00:00 2017-04-06 00:00:00
2017-04-07 00:00:00 2017-04-20 00:00:00
2017-04-21 00:00:00 2017-05-06 00:00:00
2017-05-07 00:00:00 2017-05-20 00:00:00
2017-05-21 00:00:00 2017-06-05 00:00:00
2017-06-06 00:00:00 2017-06-22 00:00:00
2017-06-23 00:00:00 2017-07-06 00:00:00
2017-07-07 00:00:00 2017-07-21 00:00:00
This code:
SELECT *
FROM
table1
WHERE
(start_date <= now() AND end_date >= now())
Displays:
2017-06-06 00:00:00 2017-06-22 00:00:00
How can I display the previous pay period? Such as:
2017-05-21 00:00:00 2017-06-05 00:00:00
This code just doesn't even look right, but I tried it anyways:
SELECT start_date,
CASE
WHEN start_date = now() THEN start_date = now() - 1
WHEN end_date = now() THEN start_date = now() - 1
END
FROM table1;
I know there is a way to use CASE WHEN
but for some reason, I cannot get the syntax right using now()
since I want it to be dynamic and not a static date.