How to get the dates of yesterday today and tomorrow?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

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

0

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:

2020-11-04
2020-11-03
2020-11-05

Relevant Projects

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

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.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

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.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

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.