3
$\begingroup$

How to change the definition of 'Weekend' to get 'True' from every Friday from 22:00:01 to Sunday 23:00:00. Example:

DayMatchQ["03-Jan-2020 22:00:00", "Weekend"](*out: 'False'*)
DayMatchQ["03-Jan-2020 22:00:01", "Weekend"](*out: 'True'*)

DayMatchQ["05-Jan-2020 23:00:00", "Weekend"](*out: 'True'*)
DayMatchQ["05-Jan-2020 23:00:01", "Weekend"](*out: 'False'*)

r:)

$\endgroup$
1
  • 1
    $\begingroup$ 601200 >= Mod[AbsoluteTime[#], 604800] > 424800 & ? $\endgroup$
    – Ben Izd
    Commented Apr 20, 2022 at 8:20

1 Answer 1

5
$\begingroup$

Here is a brief function that gives your desired output:

ClearAll[weekendQ]
weekendQ[date_] := 
 5 + 22/24 < DateValue[date, "ISOWeekDayExact"] <= 7 + 23/24

weekendQ["03-Jan-2020 22:00:00"](*out:'False'*)
weekendQ["03-Jan-2020 22:00:01"](*out:'True'*)

weekendQ["05-Jan-2020 23:00:00"](*out:'True'*)
weekendQ["05-Jan-2020 23:00:01"](*out:'False'*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.