sunshine@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 4 months agoI'm new to using Ruby and this tickled me pinklemmy.mlimagemessage-square77fedilinkarrow-up1213arrow-down17cross-posted to: [email protected]
arrow-up1206arrow-down1imageI'm new to using Ruby and this tickled me pinklemmy.mlsunshine@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 4 months agomessage-square77fedilinkcross-posted to: [email protected]
minus-squareBoomer Humor Doomergod@lemmy.worldlinkfedilinkEnglisharrow-up17·4 months agoAnd the best part is the Ruby way accounts for leap years.
minus-squaredeadbeef79000@lemmy.nzlinkfedilinkarrow-up15·4 months agoWell, 365 * 10 certainly doesn’t ;-)
minus-squareEager Eagle@lemmy.worldlinkfedilinkEnglisharrow-up7arrow-down1·4 months agoI 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.
minus-squareDiplomjodler@lemmy.worldlinkfedilinkarrow-up3arrow-down1·edit-24 months agoI’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')
minus-squareEager Eagle@lemmy.worldlinkfedilinkEnglisharrow-up2·4 months agoor just this from datetime import datetime today = datetime.today() ten_years_ago = today.replace(year=today.year - 10) print("Date 10 years ago:", ten_years_ago.date())
minus-squareDigital Mark@lemmy.sdf.orglinkfedilinkEnglisharrow-up1·4 months agoAnd what happens when you run that on Feb 29, 2024?
minus-squareEager Eagle@lemmy.worldlinkfedilinkEnglisharrow-up1·4 months agodatetime raises a ValueError when trying to create an invalid date
And the best part is the Ruby way accounts for leap years.
Well,
365 * 10certainly doesn’t ;-)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.
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?
or just this
And what happens when you run that on Feb 29, 2024?
datetime raises a ValueError when trying to create an invalid date