Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get yesterday date in node.js backend?

I am using date-format package in node back end and I can get today date using

var today = dateFormat(new Date());

In the same or some other way I want yesterday date. Still I did't get any proper method. For the time being I am calculating yesterday date manually with lot of code. Is there any other method other then writing manually ?

like image 983
Shanthi Avatar asked Aug 10 '15 06:08

Shanthi


People also ask

How can I get yesterday's date in moment?

Just like this: moment(). subtract(1, 'days') . It will give you the previous day with the same exact current time that is on your local pc. Save this answer.

How do you know if a date was yesterday?

To check if a date is yesterday:Subtract 1 day from the current date to get yesterday's date.

How can I select Yesterday date in SQL?

To get the yesterday and tomorrow of the current date we can use the CURRDATE() function in MySQL and subtract 1 from it to get yesterday and add 1 to it to get tomorrow.


1 Answers

var date=new Date();
var date=new Date(date.setDate(date.getDate()-1));
console.log(date);

This will give you same Date format, but not tested for edge case scenarios.

like image 151
Hemant Singh Avatar answered Oct 10 '22 00:10

Hemant Singh