0

I'm trying to get the difference (in days) between today and a previous date here:

from datetime import date

today = date.today() # get today's date
print("Today's date:", today)
new_today = today.strftime("%Y, %#m, %Y") # convert it so that delta.days understands
print(new_today)

f_date = date(new_today)
l_date = date(2014, 7, 11)
delta = f_date - l_date
print(delta.days)

But I get an error: TypeError: an integer is required (got type str)

I've read multiple threads on this, but they don't address using today's date in the calculation.

What's the best way to perform this calculation?

  • What exactly are you seeking to get with the difference in dates? Are you just seeking the difference in amount of days between the dates? – Paul Jan 27 '21 at 04:50
  • @Paul In days. I've edited my question to make that clear, thank you. – aidenmitchell Jan 27 '21 at 04:52
  • @sahasrara62 Not really, as using today's date as a date object isn't covered, and that's what I'm having issues with. – aidenmitchell Jan 27 '21 at 04:53

1 Answers1

1

using datetime

import datetime
x = datetime.date.today()
y = datetime.date(2014, 7, 11)  
diff = x-y
print(diff.days)

output

2392
sahasrara62
  • 10,069
  • 3
  • 29
  • 44