Manish Barnwal

...just another human

Working with dates in Python

from datetime import datetime

To convert a string to date:

`datetime.strptime('string', 'format_of_the_string')``

d1 = datetime.strptime('2017-02-02', '%Y-%m-%d')

`d2 = datetime.strptime('2018-06-17', '%Y-%m-%d')``

Find the number of days between two dates `delta = d2 - d1 delta.days ``

Difference between today and some date today = datetime.today() delta = today - d2 delta.days

Advertiser Disclosure: This post contains affiliate links, which means I receive a commission if you make a purchase using this link. Your purchase helps support my work.

Comments