Created
January 8, 2014 02:39
-
-
Save puliyadivinod/8310853 to your computer and use it in GitHub Desktop.
Get days count between two date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
def get_days_count_between_date(from_date, to_date, count=True): | |
from_date = datetime.strptime(from_date, "%Y-%m-%d %H:%M:%S").date() | |
to_date = datetime.strptime(to_date, "%Y-%m-%d %H:%M:%S").date() | |
delta = to_date - from_date | |
date_range = [ from_date + timedelta(days=i) for i in range(delta.days + 1)] | |
if count: | |
return len(date_range) | |
return date_range | |
if __name__ == '__main__': | |
print get_days_count_between_date("2013-12-30 00:00:00", "2014-01-01 00:00:00"), "days" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment