In python
how to write a program which takes a number of days from now - 100 days, and find in which month that future day is.

Recommended Answers

All 3 Replies

datetime.date.today() - datetime.timedelta(days=100)

gives you the date - 100 days.

>>> import datetime
>>> datetime.date.today()
datetime.date(2020, 4, 24)
>>> datetime.date.today() - datetime.timedelta(days=100)
datetime.date(2020, 1, 15)

You can see the month is 1.

commented: Sorry for the +1 a month late but here it is. +15

To precisely answer your question , we use a library called datetime to date related problems in python.The code below will work for you.Also it seems you are new to python so i will post a link to free tutorial of python here for beginners
Python for absolue beginners
`

import datetime
datetime.date.today()
days=input("Enter the number of days you want to skip ahead")
new_date=datetime.date.today() + datetime.timedelta(str(days))
print("The month is {}".format(new_date))
datetime_object = datetime.datetime.strptime(str(new_date.month), "%m")
month_name = datetime_object.strftime("%b")
print(month_name)

`

You can refer to the programs offered by this website. rawpython

commented: Doesn't help the OP but useful nonetheless. +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.