Computer Science, asked by Hardeep6078, 1 year ago

How to find only Monday's date with Python?

Answers

Answered by farhanimtiyaz327
0

You can find the next Monday's date easily with Python's datetime library and the timedelta object. You just need to take today's date. Then subtract the number of days which already passed this week (this gets you 'last' monday). Finally add one week to this date using a timedelta object and voila you get the next monday's date. For example,

import datetime

today = datetime.date.today()

next_monday = today + datetime.timedelta(days=-today.weekday(), weeks=1)

print(next_monday)

Similar questions