How to get the dates of yesterday today and tomorrow?

How to get the dates of yesterday today and tomorrow?

How to get the dates of yesterday today and tomorrow?

This recipe helps you get the dates of yesterday today and tomorrow


Recipe Objective

Working with datetime, we might be interested to find the dates of today, yesterday or event after 365 days from today.

So this recipe is a short example on how to get the dates of yesterday, today and tomorrow. Let's get started.

Step 1 - Import the library

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.

Step 2 - Generating dates

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.

Step 3 - Printing dates

print(today) print(yesterday) print(tomorrow)

Simply use print function to print the dates of yesterday, today and tomorrow.

Step 4 - Let's look at our dataset now

Once we run the above code snippet, we will see:


Relevant Projects

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.