numpy datetime64 add or substract date interval

You can use the numpy.timedelta64 object to perform time delta calculations on a numpy.datetime64 object, see Datetime and Timedelta Arithmetic.

Since a year can be either 365 or 366 days, it is not possible to substract a year, but you could substract 365 days instead:

import numpy as np
np.datetime64('2014-12-31') - np.timedelta64(365,'D')

results in:

numpy.datetime64('2013-12-31')

Leave a Comment