Hi,
I'm writing a program which needs to query a table, and determine if the current date/time falls inside a blackout period.
In my table, I created 2 columns as Date/Time stamps to hold my starting/ending values.
The catch is, I dont want these values to be a fixed point in time. I want them to be rolling each week. For example, I might want my blackout period to be from Wed@01:00 to Thur@13:00 ... so I scribbled the following messy SQL code:
The catch is, If my program run on the given blackout day eg. Friday, the NEXT_DAY will return friday the following week!
Surely theres an easier way!
I think de-constructing and re-constructing dates will almost always be problematic. All I want to know is if I'm in a blackout or not.
Any hints/tips welcome.
I'm writing a program which needs to query a table, and determine if the current date/time falls inside a blackout period.
In my table, I created 2 columns as Date/Time stamps to hold my starting/ending values.
The catch is, I dont want these values to be a fixed point in time. I want them to be rolling each week. For example, I might want my blackout period to be from Wed@01:00 to Thur@13:00 ... so I scribbled the following messy SQL code:
Code:
SELECT 1
FROM dwh.ms_support_control
WHERE sysdate BETWEEN TO_DATE(TO_CHAR(NEXT_DAY(sysdate,TO_CHAR(inactivity_1_start_dttm,'DAY')),'DD-MM-YYYY') || ' ' || TO_CHAR(inactivity_1_start_dttm,'HH24:MI:SS'),'DD-MM-YYYY HH24:MI:SS')
AND TO_DATE(TO_CHAR(NEXT_DAY(sysdate,TO_CHAR(inactivity_1_interval_dttm,'DAY')),'DD-MM-YYYY') || ' ' || TO_CHAR(inactivity_1_interval_dttm,'HH24:MI:SS'),'DD-MM-YYYY HH24:MI:SS')
The catch is, If my program run on the given blackout day eg. Friday, the NEXT_DAY will return friday the following week!
Surely theres an easier way!
I think de-constructing and re-constructing dates will almost always be problematic. All I want to know is if I'm in a blackout or not.
Any hints/tips welcome.