0

I get the entry date in the format "2020-12-23", type - string. I have to compare it to the current date and run the if/else condition.

code.py

curent_date = datetime.date.today()
csv_date = datetime.datetime.strptime(value, "%Y-%m-%d").date()
print(csv_date, type(csv_date))
print(curent_date, type(curent_date))
if csv_date > curent_date:
    date_error.append

get me

2029-12-24 <class 'datetime.date'>
2020-04-04 <class 'datetime.date'>

But after I get 500 error

Exception Value: time data '' does not match format '%Y-%m-%d'

What's the problem?

Mustafa
  • 977
  • 3
  • 12
  • 25
Jekson
  • 2,892
  • 8
  • 44
  • 79
  • 1
    Does value come from a csv file? It seems like you have missing (empty) values. You should have a look at the `pandas` library that will help you handle both datetime values and missing values. – FlorianGD Apr 04 '20 at 09:44
  • yes data come from csv, you're right, the problem is with the empty field. Thank you! – Jekson Apr 04 '20 at 09:46
  • 1
    print out the contents of value before the date convertion, chances are there is a value in your csv in the wrong format – Chris Doyle Apr 04 '20 at 09:52
  • I added a check with the condition if. The problem is solved. – Jekson Apr 04 '20 at 09:56

0 Answers0