0

I'm making a stock price prediction LSTM model.

I've got two dates from an input:

from datetime import datetime    
data1 = datetime.strptime(data1input, '%Y%m%d').date()
data2 = datetime.strptime(data2input, '%Y%m%d').date()

The difference in days between the two dates is 80% of the whole period, so I need to know the whole period in days and its 20%:

whole_days=round((date1.days * 100)/80)
print(whole_time)
left_days = round(whole_time * .2)
print(left_time)

Now, I'd like to know the resulting date by adding left_time days to data2. But it gives me an error. What is the correct code to do this?

data_left = data2 + datetime.timedelta(days=left_time)

type object 'datetime.datetime' has no attribute 'timedelta'
Nick is tired
  • 6,860
  • 20
  • 39
  • 51
  • 1
    Have a look at [`this`](https://stackoverflow.com/questions/12906402/type-object-datetime-datetime-has-no-attribute-datetime). – Mayank Porwal Mar 29 '21 at 13:40
  • 2
    just use `from datetime import timedelta` and use `timedelta(days=left_time)` instead of `datetime.timedelta(days=left_time)` – ThePyGuy Mar 29 '21 at 13:43

1 Answers1

0

I tried to convert the input dates to ordinal and subtract them:

data1_ord = data1.toordinal()
data2_ord = data2.toordinal()
percent80_days = data2_ord - data1_ord
percent80_days

So I just worked with ordinal dates and converted the last ordinal to a date It worked!

percent100_days=round((percent80_days * 100)/80)
percent20_days = round(percent100_days * .2)
data3_ord = data2_ord + percent20_days
data3 = datetime.fromordinal(data3_ord).date()
print(data3)