I want to compare 2 date and predict a label true if date 1 greater than date 2 and predict false date 1 less than date 2.
I have trained the model but model is predicting wrong for near by dates that is if 13-01-2020
and 14-01-2020
is given it will predict true but the right answer is false.
Asked
Active
Viewed 1,295 times
-4

userb
- 27
- 5
-
please refer this link https://stackoverflow.com/questions/8142364/how-to-compare-two-dates – Sarthak Gupta Mar 16 '20 at 06:41
-
1In what sense predict? To me prediction is saying that something will happen *before* it happens. – Ole V.V. Mar 16 '20 at 06:48
-
if date 1 greater than date 2 predict a label true else false that's all – userb Mar 16 '20 at 07:29
1 Answers
1
Try this:
import datetime
StartDate = "13-01-2020"
EndDate = "14-01-2020"
res = datetime.datetime.strptime(StartDate, '%d-%m-%Y')
res2 = datetime.datetime.strptime(EndDate, '%d-%m-%Y')
if res>res2:
print(StartDate)
elif res<res2:
print(EndDate)
Convert string into datetime format and then compare it.

Vaibhav Jadhav
- 2,020
- 1
- 7
- 20