Referring back to some of my notes, I found the following:
import numpy
dt64 = numpy.datetime64( "2011-11-11 14:23:56" )
# dt64 is internally just some sort of int
# it has no fields, and very little support in numpy
import datetime, time
dtdt = dt64.astype(datetime.datetime) # <<<<<<<< use this!
dtdt.year
dtdt.month
dtdt.day
# to convert back:
dt64 = np.datetime64(dtdt) # <<<<<<<< use this too!
dt64.item().strftime("%Y%b%d")
The modules datetime and time are normal python modules: they work reasonably well, have lots of fields, conversions, and support.
datetime64 is an incompletely implemented subtype built into numpy. It's just some sort of 64-bit int (?) (seconds since 1970 perhaps?). datetime64 is something completely different from a datetime.datetime . If you convert a datetime64 to a float and back, you are losing lots of precision (bits) -- hence the errors.
The (not part of numpy) module datetime can also do things like:
# timedelta()
delta = datetime.timedelta(days=11, hours=10, minutes=9, seconds=8)
delta # datetime.timedelta(11, 36548) # (days,seconds)
delta.days
delta.seconds
delta.microseconds
delta.total_seconds() # 986948.0
# arithmetic: +-*/
# 2 timedelta's
# timedelta and datetime
now = datetime.datetime.now()
christmas = datetime.datetime(2019,12,25)
delta = christmas - now
So let numpy sometimes store your date-data as datetime64, but I would recommend the not-numpy module datetime to work on datetime-arithmetic.