this post was submitted on 24 Aug 2025
281 points (97.6% liked)
Programmer Humor
37996 readers
89 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I don't think this is implemented in the standard datetime library, but in principle overriding sub is easily possible and you can define it as you'd wish.
However, I think subtracting a year is a bit ill defined, because it isn't clear which year you're subtracting given the leap year issue.
If you're subtracting a year from a date, you could just keep the date constant while changing the year, and adjust Feb 29 as needed.