Datetime skips certain dates

I use this method to get the date. Now I want to skip all weekends during this period and only return to the working day. What should I do?
s = datetime.date (2017 1)
e = datetime.date (2018 1)

t = datetime.timedelta (days=1)
while s < = e:

s += t

Mar.30,2021

consider the python.org/3/library/datetime.html-sharpdatetime.date.weekday" rel=" nofollow noreferrer "> weekday () method, which returns Arabic numerals for the day of the week. Note that Monday is 0 and Sunday is 6 .

reference for specific implementation:

import datetime
s = datetime.date(2017,1,1)
e = datetime.date(2018,1,1)


def get_weekdays(s,e): 
    """
    :param s 
    :param e 
    :return: datetime.datelist
    """
    result = list()
    -sharp delta1
    delta = datetime.timedelta(days=1)
    while s != e:
        s += delta
        -sharp 
        if s.weekday() in [0,1,2,3,4]:
            result.append(s)
    return result

weekdays = get_weekdays(s=s,e=e)

continue the answer from dei upstairs, and give you a code example. If you want to get the time range, for loop to assemble the string, then switch to datetime type, get the week by referring to the example below, and add an if to judge that you can skip Saturday and Sunday

.

pandas

import pandas as pd
dates = pd.date_range(start='20170101', end='20180101', freq='B')
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3be17-34697.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3be17-34697.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?