Files
30-seconds-of-code/snippets/days_ago.md
Angelos Chalaris fad8bd3e8a Update covers
2023-02-16 22:24:35 +02:00

450 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Days ago date cup-of-orange 2020-10-28T16:19:30+02:00 2020-10-28T16:19:30+02:00

Calculates the date of n days ago from today.

  • Use datetime.date.today() to get the current day.
  • Use datetime.timedelta to subtract n days from today's date.
from datetime import timedelta, date

def days_ago(n):
  return date.today() - timedelta(n)
days_ago(5) # date(2020, 10, 23)