简体   繁体   English

如何只打印工作日的日期(而不是周末),按日期打印几天范围内的日期?

[英]How to print dates of weekdays only (not weekends) for a range of days by date, for a range of months?

I need to figure out in python how to (in pesudo) 我需要在python中弄清楚如何(在pesudo中)

x = month-begin
y = month-end

for range in (x through y) 
  print(dates of weekdays - Monday trough Friday)

Use date.weekday(). 使用date.weekday()。 Following your pseudo-code example: 按照您的伪代码示例:

for day in range (x through y)
    if day.weekday() in range(0,5):
        print(day)

Use the datetime module: 使用datetime模块:

import datetime
current=datetime.datetime(2018,8,14,14,00)  
end=datetime.datetime(2018,12,1,14,00) 
while current<end:
    current+=datetime.timedelta(days=1)
    if current.weekday()<5:
        print(current.strftime("%-m/%-d"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在python中制作带有日期范围标签工作日和周末(可按日期联接)的表? - How can I make a table with a date range labeling weekdays and weekends (joinable by date) in python? 过滤日期范围(不包括周末) - Filter dates range excluding weekends 循环日期范围子+将日期分配给各自的月份 - Looping a date range sub + allocate days to their respective months Python将int添加到日期,并且仅返回工作日日期,而忽略周末 - Python add int to a date and only return weekdays date ignoring weekends 如何在 python 的日期范围内获取某些特定工作日的列表 - How to get a list of some specific weekdays within a date range in python 如何使用 Pandas 将日期范围划分为 2 个月的集合? - How to divide a date range into sets of 2 months with Pandas? 仅打印上周日期对应于工作日 - Print last week dates only corresponding to weekdays 给定日期范围,如何计算部分或全部在该范围内的周末数量? - Given a date range how to calculate the number of weekends partially or wholly within that range? 如何在 Python 中打印特定月份范围内的事务日志 - How to print transaction logs from a specific range of months in Python Pandas `bdate_range&#39; 返回包含周末的日期列表 - Pandas `bdate_range' returns list of dates that include weekends
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM