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
3 1867 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). - def future_dates(dateStr):
-
# dateStr is in the format '250208'
-
d = datetime.date(int('20'+dateStr[4:]), int(dateStr[2:4]), int(dateStr[:2]))
-
d1 = d.replace(month=d.month+1, day=3)
-
d2 = d1.replace(month=d1.month+1)-datetime.timedelta(days=3)
-
return d, d1, d2
-
-
print future_dates('250208')
Output:
>>> (datetime.date(2008, 2, 25), datetime.date(2008, 3, 3), datetime.date(2008, 3, 31))
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). - def future_dates(dateStr):
-
# dateStr is in the format '250208'
-
d = datetime.date(int('20'+dateStr[4:]), int(dateStr[2:4]), int(dateStr[:2]))
-
d1 = d.replace(month=d.month+1, day=3)
-
d2 = d1.replace(month=d1.month+1)-datetime.timedelta(days=3)
-
return d, d1, d2
-
-
print future_dates('250208')
Output:
>>> (datetime.date(2008, 2, 25), datetime.date(2008, 3, 3), datetime.date(2008, 3, 31))
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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: 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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |