import datetime
def is_weekend(date_param: str):
"""
是否是周末
@:param: date_param 日期。如 2020-01-01
"""
sd1 = '2022-11-19'
sd2 = '2022-11-20'
format = '%Y-%m-%d'
interval = 7
sd1 = datetime.datetime.strptime(sd1, format)
sd2 = datetime.datetime.strptime(sd2, format)
the_date = datetime.datetime.strptime(date_param, format)
compute_interval1 = abs((the_date-sd1).days / interval)
compute_interval2 = abs((the_date-sd2).days / interval)
return compute_interval1 == int(compute_interval1) or compute_interval2 == int(compute_interval2)
if __name__ == '__main__':
print(is_weekend('2022-03-27'))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25