Search code examples
pythondatetimestrftime

Check datetime span for weekend


I have two datetime time points for some data. I want to know if a specific day and time of the week occured on or inbetween the points. I want to specifically know if (Fri 17:00) - (Monday 07:00) occured. I can check the specic points if its the days im looking for with strftime(%a). But this would not work with the span (Thursday 12/8) - (Monday 16/8)

Is this possible to achieve somewhat easily?


Solution

  • You can use the datetime.weekday() method and datetime.hour attribute to check if your dates are in your desired range. No need to compare the string representation of the time points.