So this recipe is a short example on how to get the dates of yesterday, today and tomorrow. Let's get started.
import numpy as np
Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.
today = np.datetime64('today', 'D') yesterday = np.datetime64('today', 'D') - np.timedelta64(1, 'D') tomorrow =np.datetime64('today', 'D') + np.timedelta64(1, 'D')
Here, we have used datetime64 function and timedelta64 function of numpy library for computing dates.
print(today) print(yesterday) print(tomorrow)
Simply use print function to print the dates of yesterday, today and tomorrow.
Once we run the above code snippet, we will see:
2020-11-04 2020-11-03 2020-11-05