Currently h5py does not support a time type (FAQ, Issue).
NumPy datetime64s are 8 bytes long. So as a workaround, you could view the data as '<i8'
store the ints in the hdf5 file, and view it as a np.datetime64
upon retrieval:
import numpy as np
import h5py
arr = np.linspace(0, 10000, 4).astype('<i8').view('<M8[D]').reshape((2,2))
print(arr)
# [['1970-01-01' '1979-02-16']
# ['1988-04-02' '1997-05-19']]
with h5py.File('/tmp/out.h5', "w") as f:
dset = f.create_dataset('data', (2, 2), '<i8')
dset[:,:] = arr.view('<i8')
with h5py.File('/tmp/out.h5', "r") as f:
dset = f.get('data')
print(dset.value.view('<M8[D]'))
# [['1970-01-01' '1979-02-16']
# ['1988-04-02' '1997-05-19']]