cancel
Showing results for 
Search instead for 
Did you mean: 

difference between two timestamps, excluding weekends

oreinar
Explorer
0 Kudos
133

Hello,

i need to calculate date difference between two timestamps (date+time), excluding weekends.

i.e.

startdate = 23-02-2023 15:37:24

enddate = 28-02-2023 07:13:59

Since there is a weekend in between, I expect to have 2,65 as result, and not 4,65.

Can you please help?

This well-known formula does not work, because it's based on date only (without time):

DateTimeVar startdate := {table.startdate};

DateTimeVar enddate := {table.enddate};


Datediff("d", startdate, enddate) -

Datediff("ww", startdate, enddate, crSaturday)-

Datediff("ww", startdate, enddate, crSunday);

Thank you very much in advance.

Regards

Rani

Accepted Solutions (0)

Answers (1)

Answers (1)

DellSC
Active Contributor

Because you need to include time, you'll need to work the math in either minutes or seconds. Here's what I might try:

DateTimeVar startdate := {table.startdate};
DateTimeVar enddate := {table.enddate};

NumberVar minBetween := Datediff("n", startdate, enddate) -
  (Datediff("ww", startdate, enddate, crSaturday) * 1440)-
  (Datediff("ww", startdate, enddate, crSunday) * 1440;

Round(minBetween/1440, 0)

1440 is the number of minutes in a day.

-Dell

oreinar
Explorer
0 Kudos

Hi Dell,

good idea indeed!

Thanks a lot for your suggestion.
I will now have to fit it all into a series of if-then-else and then test it 😉

Thanks again!