Hi Friends đź‘‹,
Welcome To Infinitbility! ❤️
To get yesterday date in moment js, pass -1
and days
in moment().add()
method it will subtract 1 day in current date and return yesterday date.
Just import a moment in your file and use moment().add(-1, 'days')
to get yesterday date.
1moment().add(-1, 'days')
Today, I’m going to show How do I get yesterday’s date in moment js, here I will use the momentjs common method moment().add()
to show yesterday’s date.
Let’s start the today’s tutorial How do you get yesterday’s date in moment js?
Table of content
- Installation
- Example in reactjs
Installation
Use the below installation command as per your package manager, moment support npm, Yarn, NuGet, spm, and meteor.
1npm install moment --save # npm2yarn add moment # Yarn3Install-Package Moment.js # NuGet4spm install moment --save # spm5meteor add momentjs:moment # meteor
Example in reactjs
In the following example, we are going to do
- import the moment package
- example of show yesterday date with format
yyyy-mm-DD
let’s write the code.
1import moment from "moment";23function App() {4 return (5 <div>6 {/* example of show yesterday date with format `yyyy-mm-DD` */}7 {moment().add(-1, 'days').format("yyyy-mm-DD")}8 </div>9 );10}1112export default App;
Note: By default, add() method is used for addition in date that’s why we are passing -1 to get yesterday’s date
In the above program, we call the moment().add(-1, 'days')
and format("yyyy-mm-dd")
methods to show formated yesterday date.
let’s check the output.

I hope it’s help you, All the best 👍.
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.