this post was submitted on 24 Aug 2025
273 points (97.6% liked)

Programmer Humor

38523 readers
404 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Semi_Hemi_Demigod@lemmy.world 32 points 1 month ago (9 children)

And the best part is the Ruby way accounts for leap years.

[–] eager_eagle@lemmy.world 10 points 1 month ago (4 children)

I prefer the one on the left because it's evident it doesn't account for leap days, while I'd be questioning whether the one on the right does.

[–] Diplomjodler3@lemmy.world 4 points 1 month ago* (last edited 1 month ago) (3 children)

I'll give it a shot. Looks a bit kludgy and I've been typing this on my phone while sitting on the toilet. What am I doing with my life?

from datetime import datetime 

now = datetime.now()
year = now.strftime('%Y')
month = now.strftime('%m')
day = now.strftime('%d')
tenyearsago = datetime(year-10, month, day)
print(tenyearsago.strftime('%d.%m.%Y')
[–] mdhughes@lemmy.sdf.org 4 points 1 month ago (1 children)

And what happens when you run that on Feb 29, 2024?

[–] eager_eagle@lemmy.world 2 points 1 month ago

datetime raises a ValueError when trying to create an invalid date

load more comments (1 replies)
load more comments (1 replies)
load more comments (5 replies)