on 2023 Feb 28 6:42 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
57 | |
11 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.