How to use 'python datetime weekday' in Python

Every line of 'python datetime weekday' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
31def next_weekday(d, weekday):
32 """
33 Given a starting timestamp d and a weekday number d (0-6)
34 return the timestamp of the next time this weekday is going to happen
35 """
36 days_ahead = weekday - d.weekday()
37 if days_ahead <= 0: # Target day already happened this week
38 days_ahead += 7
39 return d + datetime.timedelta(days_ahead)

Related snippets