# Help with WORKDAY()

Hello, could someone help me with this:
I have a creation date [FECHA DE CREACION].
I want to get a deadline [FECHA LIMITE], adding 8 hours from the creation date.
But I want the deadline to contemplate only business days from Monday to Friday and a schedule from 9:00 a.m. to 6:00 p.m.

I already tried workday, but Iβm not getting what Iβm looking for.

Please try the below expression in [FECHA LIMITE]. You could make it more compact with more testing. Please test well.

IF(TIME( [FECHA DE CREACION])<=β10:00:00β,
[FECHA DE CREACION] + β008:00:00β,
DATETIME(WORKDAY(DATE( [FECHA DE CREACION]),1) + β009:00:00β) +
(β008:00:00β - (DATETIME(DATE( [FECHA DE CREACION])-β006:00:00β) -
[FECHA DE CREACION])
)
)

2 Likes

Thank you very much friend @Suvrutt_Gurjar ,
I made some modifications since if the item was generated one day I did not work, I took it as a day work, here I leave it in case it can be useful to someone.

IF(
OR(WEEKDAY(DATE([FECHA DE CREACION]))=1,WEEKDAY(DATE([FECHA DE CREACION]))=7),
DATETIME(WORKDAY(DATE([FECHA DE CREACION]),1)+β017:00:00β),
IF(
AND(AND(WEEKDAY(DATE([FECHA DE CREACION]))<>1,WEEKDAY(DATE([FECHA DE CREACION]))<>7),
TIME([FECHA DE CREACION])<β09:00:00β),DATE([FECHA DE CREACION])+β017:00:00β,
IF(
AND(TIME([FECHA DE CREACION])>=β09:00:00β,TIME([FECHA DE CREACION])<=β10:00:00β),
[FECHA DE CREACION]+β008:00:00β,
IF(
AND(TIME([FECHA DE CREACION])>β10:00:00β,TIME([FECHA DE CREACION])<=β18:00:00β),
DATETIME(WORKDAY(DATE([FECHA DE CREACION]),1)+β009:00:00β+(β008:00:00β-(DATETIME(DATE([FECHA DE CREACION])+β018:00:00β)-[FECHA DE CREACION])))
,
IF(TIME([FECHA DE CREACION])>β16:00:00β,DATETIME(WORKDAY(DATE([FECHA DE CREACION]),1)+β017:00:00β),
[FECHA DE CREACION]
)
)
)
)
)

2 Likes

You are welcome. Thank you for posting your final expression @Cesar_Hernandez . It will certainly help anyone reading this post thread in the future.

1 Like

Hereβs your expression, reformatted to my preferences:

``````IF(
OR(
(WEEKDAY(DATE([FECHA DE CREACION])) = 1),
(WEEKDAY(DATE([FECHA DE CREACION])) = 7)
),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
IF(
AND(
AND(
(WEEKDAY(DATE([FECHA DE CREACION])) <> 1),
(WEEKDAY(DATE([FECHA DE CREACION])) <> 7)
),
(TIME([FECHA DE CREACION]) < β09:00:00β)
),
(DATE([FECHA DE CREACION]) + β017:00:00β),
IF(
AND(
(TIME([FECHA DE CREACION]) >= β09:00:00β),
(TIME([FECHA DE CREACION]) <= β10:00:00β)
),
([FECHA DE CREACION] + β008:00:00β),
IF(
AND(
(TIME([FECHA DE CREACION]) > β10:00:00β),
(TIME([FECHA DE CREACION]) <= β18:00:00β)
),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β009:00:00β
+ (
β008:00:00β
- (
DATETIME(
DATE([FECHA DE CREACION])
+ β018:00:00β
)
- [FECHA DE CREACION]
)
)
),
IF(
(TIME([FECHA DE CREACION]) > β16:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
[FECHA DE CREACION]
)
)
)
)
)
``````

The test expressions of your IF() expressions are a bit redundant, so can be simplified to improve efficiency. Your inner IF() expressions test to confirm that the outer IF() expressions failed, which is unnecessary. If the inner IF() is reached, we know the outer IF() failed, so we donβt need to test again.

``````IF(
OR(
(WEEKDAY(DATE([FECHA DE CREACION])) = 1),
(WEEKDAY(DATE([FECHA DE CREACION])) = 7)
),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
IF(
(TIME([FECHA DE CREACION]) < β09:00:00β),
(DATE([FECHA DE CREACION]) + β017:00:00β),
IF(
(TIME([FECHA DE CREACION]) <= β10:00:00β),
([FECHA DE CREACION] + β008:00:00β),
IF(
(TIME([FECHA DE CREACION]) <= β18:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β009:00:00β
+ (
β008:00:00β
- (
DATETIME(
DATE([FECHA DE CREACION])
+ β018:00:00β
)
- [FECHA DE CREACION]
)
)
),
IF(
(TIME([FECHA DE CREACION]) > β16:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
[FECHA DE CREACION]
)
)
)
)
)
``````

Nested IF() expressions can often be rewritten with IFS() instead, which can improve readability and reduces parentheses:

``````IFS(
OR(
(WEEKDAY(DATE([FECHA DE CREACION])) = 1),
(WEEKDAY(DATE([FECHA DE CREACION])) = 7)
),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
(TIME([FECHA DE CREACION]) < β09:00:00β),
(DATE([FECHA DE CREACION]) + β017:00:00β),
(TIME([FECHA DE CREACION]) <= β10:00:00β),
([FECHA DE CREACION] + β008:00:00β),
(TIME([FECHA DE CREACION]) <= β18:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β009:00:00β
+ (
β008:00:00β
- (
DATETIME(
DATE([FECHA DE CREACION])
+ β018:00:00β
)
- [FECHA DE CREACION]
)
)
),
(TIME([FECHA DE CREACION]) > β16:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
TRUE,
[FECHA DE CREACION]
)
``````

The initial OR() can be replaced with IN() to avoid computing the same value twice:

``````IFS(
IN(WEEKDAY(DATE([FECHA DE CREACION])), LIST(1, 7)),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
(TIME([FECHA DE CREACION]) < β09:00:00β),
(DATE([FECHA DE CREACION]) + β017:00:00β),
(TIME([FECHA DE CREACION]) <= β10:00:00β),
([FECHA DE CREACION] + β008:00:00β),
(TIME([FECHA DE CREACION]) <= β18:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β009:00:00β
+ (
β008:00:00β
- (
DATETIME(
DATE([FECHA DE CREACION])
+ β018:00:00β
)
- [FECHA DE CREACION]
)
)
),
(TIME([FECHA DE CREACION]) > β16:00:00β),
DATETIME(
WORKDAY(DATE([FECHA DE CREACION]), 1)
+ β017:00:00β
),
TRUE,
[FECHA DE CREACION]
)
``````

My interpretation of this expression is:

1. If `[FECHA DE CREACION]` is a Saturday or Sunday, return 5pm of the first workday following.

Beyond here, we know `[FECHA DE CREACION]` is not a Saturday or Sunday.

1. If `[FECHA DE CREACION]` is before 9am, return 5pm of that same day.

Beyond here, we know `[FECHA DE CREACION]` is not a Saturday or Sunday and is not before 9am.

1. If `[FECHA DE CREACION]` is not after 10am, return 8 hours after `[FECHA DE CREACION]`.

Beyond here, we know `[FECHA DE CREACION]` is not a Saturday or Sunday and is after 10am.

1. If `[FECHA DE CREACION]` is not after 6pm, return a time on the next workday equal to 9am plus 8 hours minus the time on the date of `[FECHA DE CREACION]` before 6pm. (I may have misrepresented that: itβs kinda difficult to explain what youβre doing, but I see what youβre trying to do, and I think you did it correctly.)

Beyond here, we know `[FECHA DE CREACION]` is not a Saturday or Sunday and is after 6pm.

1. If `[FECHA DE CREACION]` is after 4pm, return 5pm of the next workday. Note that the time on this condition is before the previous condition, so even though this condition says after 4pm, after 4pm to 6pm is handled by the previous condition. In effect, this condition only catches `[FECHA DE CREACION]` times after 6pm.

By here, all conditions have been handled, so the following should never happen.

1. Return the original `[FECHA DE CREACION]`.
5 Likes

Thank you very much! @Steve , you were right, your formula is much more efficient

2 Likes