我想获取两个日期之间的所有日期,但不包括周末日期。 以下是日期格式:
last_date = '2019-01-21'
curr_date = '2019-02-04'
答案 0 :(得分:2)
将星期几返回为整数,其中星期一为0,星期日为 是6。
from datetime import timedelta, date
def daterange(date1, date2):
for n in range(int ((date2 - date1).days)+1):
yield date1 + timedelta(n)
start_dt = date(2019,1,21)
end_dt = date(2019,2,4)
weekdays = [5,6]
for dt in daterange(start_dt, end_dt):
if dt.weekday() not in weekdays: # to print only the weekdates
print(dt.strftime("%Y-%m-%d"))
编辑:
将星期几作为整数返回,其中星期一为1,星期日为 是7。
weekdays = [6,7]
for dt in daterange(start_dt, end_dt):
if dt.isoweekday() not in weekdays:
print(dt.strftime("%Y-%m-%d"))
输出:
2019-01-21
2019-01-22
2019-01-23
2019-01-24
2019-01-25
2019-01-28
2019-01-29
2019-01-30
2019-01-31
2019-02-01
2019-02-04
答案 1 :(得分:0)
示例:
var firestore = Firestore.instance;
firestore.collection('student').document('attendance').updateData({'total_attendace': FieldValue.increment(1)});
结果:
from dateutil.parser import parse
from dateutil.rrule import rrule, DAILY, MO, TU, WE, TH, FR
last_date = '2019-01-21'
curr_date = '2019-02-04'
result = rrule(
DAILY,
byweekday=(MO,TU,WE,TH,FR),
dtstart=parse(last_date),
until=parse(curr_date)
)
print(list(result))