473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calculating future dates

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

Feb 2 '07 #1
4 3724
On Feb 1, 6:51 pm, "Toine" <bapo...@gmail.comwrote:
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))

Feb 2 '07 #2
Toine wrote:
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.
>>import datetime
print datetime.date.today()+datetime.timedelta(days=31)
2007-03-05
>>>

---Irmen
Feb 2 '07 #3
On Feb 1, 4:54 pm, "Dan Bishop" <danb...@yahoo.comwrote:
On Feb 1, 6:51 pm, "Toine" <bapo...@gmail.comwrote:
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))
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

Feb 2 '07 #4
"Toine" <ba*****@gmail.comwrites:
On Feb 1, 4:54 pm, "Dan Bishop" <danb...@yahoo.comwrote:
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))
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.
>>import datetime
str(datetime.date.today() + datetime.timedelta(31))
--
\ "How many people here have telekenetic powers? Raise my hand." |
`\ -- Emo Philips |
_o__) |
Ben Finney

Feb 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
10
by: riki | last post by:
hello, i need to calculate num of days between 2 dates... i get separate parts of dates from html form, then i need to "make" begining and ending date and calculate difference between them......
1
by: jlm | last post by:
I have a form which feeds table (TblEmpLeave) of Employee Leave Time (time taken off for Administrative, Annual, Sick, Compensation leave). I have EmpID, LeaveDate, LeaveType, LeaveHours fields on...
2
by: bufbec | last post by:
I have worked on this for hours and can't come up with a solution. Hope someone can help me. I have a table called TMBS_HMAUDIT_PARMS. this table contains data to tell me how often a person is...
2
by: Carl | last post by:
Hi, I have a query that produces an output similar to the sample shown below. These records are based on certain criteria and a date range selected from a form. I need to create some kind of...
4
by: Yotam | last post by:
Hi, I need some help with JS. I will be grateful, if you can help me out. I have two date fields (check in, check out) and "number of days" field. I want the script to calculate automatically...
9
by: mankolele | last post by:
Hi all I need an idea on where to start when calculating a total amount betwee n two dates from a database like I want amount of money paid out from 30/03/2004 and 30/07/2004 ,but in the database...
3
by: mlcampeau | last post by:
Hi guys, I am trying to run a query that calculates when employees become eligible for supplemental vacation. This occcurs once the employee has reached 5, 10, 15, etc years of service. I got the...
2
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.