Feed on
Posts
Comments

to subtract days from a datetime object in python:

from datetime import date, timedelta
d=date.today()-timedelta(days=days_to_subtract)

thanks steve b.!


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

One Response to “subtract day from datetime in python”

  1. on 01 Jun 2018 at 9:04 am hugo

    thx to bad you can’t just put a negative value like this:
    timedelta(days=-2) i mean it would be so mutch faster.

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.