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 answers
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
- Iterate through rows in excel spreadsheet and find the difference in time when values in a different column are zero
- Python datetime.replace() has unexpected behaviour when uploading to Firebase Firestore
- mktime resulting in OverflowError: mktime argument out of range
- Drawing 2 times from a csv and subtracting them with groupby
- Current Timestamp in Azure Databricks Notebook in EST
- set_index to date with dask dataframe to circumvent memory error
- DateTime conversion (March 5, 2024, 5:33 a.m. to datetime.datetime(2024, 3, 5, 5, 33))
- Python - possible datetime value issue upon organizing data for dashboard creation/defining KPI metrics
- Can't calculate the difference between two dates using datetime
- Replacing NaN in dataframe with datetime index by dict doesn't work
- I am getting value error while parsing it to date time format in pandas
- Labelling data set with year, month,date and times
- How to catch DateParseError in pandas?
- How to label the x-axis only with hour:min in matplotlib (using datetime)?
- Get the local time without daylight savings applied, using the latest methodology
Related Questions in PYTHON-DATEUTIL
- I want None values for the fields "parseutil.parser" fails to parse, instead of default values
- Parse datetime string in python ---> Fri Dec 01 2023 00:00:00 GMT 0530 (India Standard Time)
- pandas.isin with datetime as condition gives False (bound method Timestamp.date of Timestamp???)
- How to use dateutil parser in Pyspark dataframe
- Need to convert a datetime.tzinfo *region* to a ZoneInfo region
- How can I fix error "Invalid rrule byxxx generates an empty set." using a MinuteLocator for matplotlib plots?
- speed up parse function dateutil
- Dateutil Parser return datetime object when it should have returned None
- How can I add a timedelta to a datetime when using dateutil.tz/zoneinfo and account for DST?
- What is the difference between relativedelta() and DateOffset()
- python datetul timezone results in a wrong hour
- How do I check whether a date input includes days in Python?
- dateutil not parsing my timezone correctly
- dateutil: No module named 'dateutil' error when Pandas installing using pipenv
- Why is dateutil.parser returning the incorrect date in python?
Related Questions in RELATIVEDELTA
- Unexpected behavior from pythons relativedelta and datetime libraries
- Why Python relativedelta perform like this?
- Python dateutils relativedelta incorrect result when starting with 30 day month
- TypeError: unsupported operand type(s) for +: 'DatetimeArray' and 'relativedelta'
- How can I find the elapsed business hours between two dates using pandas' CustomBusinessHour objects?
- Creating a generic code and avoiding redundancies while calling relativedelta with different arguments
- How do I go about incrementing a datetime value by one month using 'relativedelta(months=1)' without affecting the numerical day value?
- how to use Python relativedelta(or other ways) calculate 'Date after Months' in this dataframe?
- Wrong timezone shift after adding a time delta over DST
- Relativedelta 28 february and 29 february
- Python : Subtract 1 month from date
- pass two df columns through **kwargs and *args to create a new date column using relativedelta
- Aggregate elements of a list containing relativedelta objects
- Incompatibility of relativedelta
- Question about dateutil.relativedelta - Why the ouput is always zero?
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?
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)
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.