Menu

gitpiper

add_days python Code Snippet in 2024

dateintermediate

Last Updated: 17 December 2024

Calculates the date of n days from the given date.

  • Use datetime.timedelta and the + operator to calculate the new datetime.datetime value after adding n days to d.
  • Omit the second argument, d, to use a default value of datetime.today().
from datetime import datetime, timedelta def add_days(n, d = datetime.today()): return d + timedelta(n)
from datetime import date add_days(5, date(2020, 10, 25)) # date(2020, 10, 30) add_days(-5, date(2020, 10, 25)) # date(2020, 10, 20)

python snippet similar to add_days For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️