Calculating future dates

T

Toine

Hello,

I'm new to Python so please bare with me...

I need to calculate a date that is exactly 31 days from the current
date in YYYY-MM-DD format. I know that date.today() returns the
current date, but how can I add 31 days to this result? I'm sure this
task is simple, but I haven't been able to figure it out.

Thanks
 
D

Dan Bishop

Hello,

I'm new to Python so please bare with me...

I need to calculate a date that is exactly 31 days from the current
date in YYYY-MM-DD format. I know that date.today() returns the
current date, but how can I add 31 days to this result? I'm sure this
task is simple, but I haven't been able to figure it out.

Thanks

str(datetime.date.today() + datetime.timedelta(31))
 
I

Irmen de Jong

Toine said:
Hello,

I'm new to Python so please bare with me...

I need to calculate a date that is exactly 31 days from the current
date in YYYY-MM-DD format. I know that date.today() returns the
current date, but how can I add 31 days to this result? I'm sure this
task is simple, but I haven't been able to figure it out.


---Irmen
 
T

Toine

str(datetime.date.today() + datetime.timedelta(31))

Your example gave me a few errors but I was able to adapt it into
this:

str(date.today() + timedelta(31))

Thanks for your help
 
B

Ben Finney

Toine said:
Your example gave me a few errors but I was able to adapt it into
this:

str(date.today() + timedelta(31))

That only works if you're importing 'date' and 'timedelta' into the
current namespace. It's better to keep them in the 'datetime'
namespace, so it's clear what comes from where.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top