Home > Example, Python, Source code > Days between two dates

Days between two dates

Just a quick python function to calculate the days between two dates. It is really simple and easy :)

import datetime

def date_diff_days(from_date=datetime.date.today(),to_date=datetime.date.today() ):
    return (to_date - from_date).days

And an example to use it:

date1 = datetime.date(2009, 03, 26) 
date2 = datetime.date(2009, 07, 25) 

print date_diff_days( date1, date2 )

That’s it :)

Advertisement
Categories: Example, Python, Source code Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.