473,408 Members | 1,826 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,408 software developers and data experts.

How Do I Retreive Future Dates

6
Hi guys

I am hoping that someone can help me with the following.

I am a new developer to python and I have the following problem:
I have been able to retrieve a certain date from an oracle database that I am connected to.
This date is the basis for the following information that I need:
- I need to get the date of the 3rd of the month after the date I retrieve.
- I also need to get the 1st and last days of the month after the date that I retrieve.

e.g - i got the following date 250208
i need to get the 1st of march - 3rd march - 31st march

This is an example, so I will be using variables to plug in any value I want.

I have tried to see which date function could help, but with no success.

Any assistance will be highly appreciated.

Thanks
Yudesh
Mar 3 '08 #1
3 1867
dazzler
75
have you tried using datetime module?

here's some examples
http://pleac.sourceforge.net/pleac_p...sandtimes.html
Mar 3 '08 #2
bvdet
2,851 Expert Mod 2GB
Hi guys

I am hoping that someone can help me with the following.

I am a new developer to python and I have the following problem:
I have been able to retrieve a certain date from an oracle database that I am connected to.
This date is the basis for the following information that I need:
- I need to get the date of the 3rd of the month after the date I retrieve.
- I also need to get the 1st and last days of the month after the date that I retrieve.

e.g - i got the following date 250208
i need to get the 1st of march - 3rd march - 31st march

This is an example, so I will be using variables to plug in any value I want.

I have tried to see which date function could help, but with no success.

Any assistance will be highly appreciated.

Thanks
Yudesh
The first thing you need to do is parse the string into a format that can be passed to datetime.date(). This returns a date object. To get the third of the next month, you can use the date method replace(). To get the last day of the next month, you can again use the date method replace() and subtract datetime.timedelta(days=3).
Expand|Select|Wrap|Line Numbers
  1. def future_dates(dateStr):
  2.     # dateStr is in the format '250208'
  3.     d = datetime.date(int('20'+dateStr[4:]), int(dateStr[2:4]), int(dateStr[:2]))
  4.     d1 = d.replace(month=d.month+1, day=3)
  5.     d2 = d1.replace(month=d1.month+1)-datetime.timedelta(days=3)
  6.     return d, d1, d2
  7.  
  8. print future_dates('250208')
Output:

>>> (datetime.date(2008, 2, 25), datetime.date(2008, 3, 3), datetime.date(2008, 3, 31))
Mar 3 '08 #3
Yudesh
6
Hi

Thanks a lot for the assistance - I have incorporated this into my script - I will now try to format the date in a way that is needed for my project.

Thanks Again:


The first thing you need to do is parse the string into a format that can be passed to datetime.date(). This returns a date object. To get the third of the next month, you can use the date method replace(). To get the last day of the next month, you can again use the date method replace() and subtract datetime.timedelta(days=3).
Expand|Select|Wrap|Line Numbers
  1. def future_dates(dateStr):
  2.     # dateStr is in the format '250208'
  3.     d = datetime.date(int('20'+dateStr[4:]), int(dateStr[2:4]), int(dateStr[:2]))
  4.     d1 = d.replace(month=d.month+1, day=3)
  5.     d2 = d1.replace(month=d1.month+1)-datetime.timedelta(days=3)
  6.     return d, d1, d2
  7.  
  8. print future_dates('250208')
Output:

>>> (datetime.date(2008, 2, 25), datetime.date(2008, 3, 3), datetime.date(2008, 3, 31))
Mar 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
8
by: Bob Stearns | last post by:
My client wants to disallow a birth date in the future. First I tried the obvious: ALTER TABLE IS3.ANIMALS ADD CONSTRAINT b_d_f CHECK (birth_date<=current_date) It failed because special...
8
by: MLH | last post by:
Anybody's solution would be appreciated. Pls, do not pause to write anything for this. I'm not looking for that kind of a handout. I have an idea about how to do it, but I wanted to see if anyone...
253
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...
3
by: NDayave | last post by:
How Do, Is there any way to get a drop down menu to show all dates into the future, without entering them into a table beforehand? I really don't want to use the calendar control, but I need to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.