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 ?
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.
To check if a date is yesterday:Subtract 1 day from the current date to get yesterday's date.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With