1

so I am pretty new to coding, but seriously I do not see where I am heading wrong with my code.

So what I want to do is an operation where I subtract 365 days from a specific day. Thats the easy part. But when I start to import my array with all the timestamps - it doesn't recognize them. Funnily if I just type in the timestamp by hand, it does!!

What I wrote looks like this:

r= '2016-12-22 00:00:00'
u = datetime.strptime(r,"%Y-%m-%d %H:%M:%S")
d = timedelta(days=365)
print (u-d)

The result:

2015-12-23 00:00:00

But when I use an indexing command such as:

r= p_dates[254] 

which is EXACTLY the same as:

print(p_dates[254])
2016-12-22 00:00:00

It returns an Error:

strptime() argument 1 must be str, not Timestamp

Seriously - what the heck is happening :D Would be glad, if somebody can help a noob out.

Thanks in advance and happy holidays

1 Answer 1

1

It says that the first argument needs to be of str type. You can check the type of any variable like type(variable). Here just cast to a string from a timestamp

u = datetime.strptime(str(r),"%Y-%m-%d %H:%M:%S")
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.