I have a datetime64 t
that I'd like to represent as a string.
When I call strftime like this t.strftime('%Y.%m.%d')
I get this error:
AttributeError: 'numpy.datetime64' object has no attribute 'strftime'
What am I missing? I am using Python 3.4.2 and Numpy 1.9.1
Importing a data structures library like pandas to accomplish type conversion feels like overkill to me. You can achieve the same thing with the standard datetime module:
import numpy as np import datetime t = np.datetime64('2017-10-26') t = t.astype(datetime.datetime) timestring = t.strftime('%Y.%m.%d')
Use this code:
import pandas as pd t= pd.to_datetime(str(date)) timestring = t.strftime('%Y.%m.%d')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With