473,624 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3741
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.da te.today() + datetime.timede lta(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.t oday()+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.da te.today() + datetime.timede lta(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.da te.today() + datetime.timede lta(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.timede lta(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
12671
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 help me with a solution. This is what I am trying to do: Pretty much, there are two dates in my database, a start date, and an end
242
13323
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 comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
10
6630
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... something like this, in sybase: DAYS(YMD(?YEAR?,?MONTH?,?DAY?), YMD(?YEAR1?,?MONTH1?,?DAY1?)) thnx
1
2372
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 this form. Any employee can have multiple entries in the table (key fields are EmpID and LeaveID) for multiple dates (John Doe can take 3 days annual leave, then take 3 days sick leave in any given month. I have a BeginningBalance of hours that...
2
2945
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 allowed to receive services for various programs we offer. columns in this table include PROGRAM_NAME, PROGRAM_ID, ALLOWED_PER_MONTHS. In the ALLOWED_PER_MONTHS column, a numerical value of '9' in the 'ALLOWED PER MONTHS' column means a person is...
2
2085
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 calcualtion or record manipulation to do the following: I need to subtract dates from one another, for example for ID 1 I want to find the difference between 24-Jun-04 and 25-Jan-06 for the 2 applications for Person1.
4
1476
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 the difference. For example: I have defaults dates, and I want the script to put the difference in "number of days" field. And if the user will change the date, the number of days will change automatically.
9
2452
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 these dates are not captured as they come they are mixed as some may come two years later to be captured. I have to go throught the database taking in those apropriate dates I need and add them up. I belive I need to use a while loop and add the...
3
2146
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 query running great, it shows the correct dates, (5, 10, etc years after the HireDate) but I just found out that they don't want to know the exact anniversary date. People become entitled to their vacation January 1st of the year of their anniversary...
2
5850
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 for each 'month' in the quarter, hence, I want to calculate the begin & end of the month dates for April, May & June 2003 : so my starting point is: firstMonthBegin = vcBegMM & "/" & vcBegDD & "/" & vcBegYY firstMonthEnd = vcEndMM &...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.