On 2022-06-21 05:29:52 +0100, Paulo da Silva wrote: > I implemented a part of a script to subtract n months from datetime. > Basically I subtracted n%12 from year and n//12 from the month adding 12 > months when it goes<=0. Then used try when converting to datetime again. So, > if the day is for example 31 for a 30 days month it raises a ValuError > exception. Then I subtract 1 to day and repeat.
For a recent longish discussion of that matter see the threads starting at https://mail.python.org/pipermail/python-list/2022-April/905985.html and https://mail.python.org/pipermail/python-list/2022-April/906045.html (the latter also contains some prototype code). (I apologize for not pursuing that further at the time. I wanted to bolster that case with some real world applications, but I was a bit swamped with Real Work⢠and didn't find anything suitable.) hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list