enter image description here The code I wrote above works fine except I want the numerical day (%d) of the month to stay unchanged (30th) for all the months bar February (28th). The fact that the day value remains 28 after the month February is causing my 'while' loop condition to do one more iteration because the value of 'open_date' will not equal the 'maturity date' as a result of the day value changing from 30 to 28. The 'while' loop condition becomes (2026-06-28 < 2026-06-30) when it was supposed to be (2026-06-30 < 2026-06-30) at which point it evaluates to 'False' and the date 2026-06-30 would be the last item in the list as intended. So how can I use the 'relativedelta' function to only increment the month without affecting the day?
1
There are 1 best solutions below
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in WHILE-LOOP
- Reversing a number in Python
- Not clicking when user presses mouse button
- How to make a loop, repeat a loop again for my nims
- I am trying to make a Turtle Eater Game and I'm running into a minor bug(kind of)
- I cant start the first loop again on python
- Avoiding Loops in SQL, #temptables?
- Better way to exit do-while loop?
- While-loop in Python script not working when a record is added in MySQL table from triggers
- Find lexicographically smallest palindrome for a given string
- Why does it keep looping
- Creating a WHILE-Loop with a dynamic number of conditions in Python
- In Blazor server side app, I have endless while loop for consuming data from Kafka topic in my razor.cs page. How can I prevent it blocking the UI?
- Getting stuck in Python while loop
- I'm trying to write a simple program that picks a random number between 1 and 10 and gives the user to guess it
- Recreating strncpy()
Related Questions in PYTHON-DATETIME
- Trying to return 'datetime.date' instead using yield
- Converting localized string date representation to UTC in python
- datetime.fromtimestamp vs datetime.utcfromtimestamp, which one is safer to use?
- Incorrect conversion from epoch time when scraping web
- Seconds left to HH:MM
- In python how can I get the date and time of my local server?
- Converting the format of a date string
- When importing from a python module is it a class that gets imported or a function?
- Would I be able to check if the time is between 12:00 and 13:00 using datetime?
- Retrieve data from mongodb based on date condition in pymongo
- Convert timezone of multiple columns in a pandas DataFrame according to a third column?
- Extracting hour, date and month from a pandas (python) DataFrame object
- Python retrieve DayOfWeek as integer
- Converting datetime string to datetime in numpy (python)
- Convert a datetime.timedelta into ISO 8601 duration in Python?
Related Questions in PYTHON-DATEUTIL
- Timezone offset sign reversed by dateutil?
- Django - F('datetimefield') + relativedelta(months=1) fails
- How to ignore python module in ~/.local/lib/python2.7/site-packages?
- How to import dateutil?
- Python Dateutil parse() parameters
- Why does a call to dateutil.parser.parse indicate november is december?
- Pandas can't find dateutil.parser after Mavericks
- Getting timezone from dateutil.parser.parse in Python
- is it possible to have dateutil.parser.parse only parse iso8601 strings and throws error for other formats
- Python. from dateutil.relativedelta import * works in shell but not in a script
- Extraction of some date formats failed when using Dateutil in Python
- set up Darwin Calendar Server get an error about "MD5 sum for download file..."
- Python time zones: Why is EST off by one hour? (pytz / dateutil)
- dateutil seems to give wrong timezone
- Python dateutil, check which value is given
Related Questions in RELATIVEDELTA
- Django - F('datetimefield') + relativedelta(months=1) fails
- Strange arithmetic with relativedelta for date calculations
- Get first and last date of previous month in Django
- python relativedelta get the wrong result
- Cannot reconstitute end date with dateutil relativedelta
- Question about dateutil.relativedelta - Why the ouput is always zero?
- Python dateutils relativedelta incorrect result when starting with 30 day month
- Not all dates are captured when filtering by dates. Python Pandas
- Relativedelta 28 february and 29 february
- Weird arithmetic with datetimes and relativedelta
- Construct date based on week_of_month and day_of_week criteria
- Wrong timezone shift after adding a time delta over DST
- TypeError: unsupported operand type(s) for +: 'DatetimeArray' and 'relativedelta'
- Python Dataframe Date plus months variable which comes from the other column
- Python method to create a dateutil.relativedelta.relativedelta object from a dict
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Documentation for relativedelta shows also
day=to set day (don't usedays=which add days)Minimal working code
Result:
Eventually you should use original date and add
months=1,months=2, etc.