Hi,
I have to calculate the number of hours between two dates and exclude Saturday and Sunday. The first 24 hours (Monday, Tuesday, Wednesday, Thursday or Friday) of the calculation is a grace period. After the first 24 hours, is the calculation for over of compliance.
For example:
Notified: 2019-02-03 08:58:00.0000000 (is a Sunday)
Entered: 2019-02-05 08:38:00.0000000 (is a Tuesday)
Since 2/3/2019 is a Sunday, the time shouldn’t start counting until 2/4 at 00:01. There’s then the 24 hour grace period, so it becomes out of compliance on 2/5/2019 at 00:02. It should only be 9 hours out of compliance.
The query in The SQL runs fine for Monday - Friday. It's not excluding Saturday and Sunday.
Below is the SQL code for the number of hours:
DATEDIFF(hour,CAST(tbla.NOTIFYDATE AS DATETIME) +
CAST(Coalesce(tbla.NOTIFYTIME,'23:59:00') AS DATETIME),
CAST(tbla.ENTRYDATE AS DATETIME) +
CAST(Coalesce(tbla.ENTRYTIME,'23:59:00') AS DATETIME)) - ( (DATEDIFF(wk, tbla.NOTIFYDATE,
tbla.ENTRYDATE) * 2)-(CASE WHEN DATENAME(dw, tbla.NOTIFYDATE) = 'Sunday' THEN 1 ELSE 0 END)-
(CASE WHEN DATENAME(dw, tbla.ENTRYDATE) = 'Saturday' THEN 1 ELSE 0 END)) * 24 - 24 AS timelyOOCHours
Is there a way to perform the calculation in Cold Fusion 2016?
Can DateDiff do this? If so, is there an example?