How can I calculate yesterday as a date in JavaScript?
How do you get yesterdays' date using JavaScript? We use the setDate() method on yesterday , passing as parameter the current day minus one. Even if it's day 1 of the month, JavaScript is logical enough and it will point to the last day of the previous month.
You can get yesterday's Date by following approach Answered by Jiger Joshi. And by using new Timestamp(java. util. Date) you can get yesterday's timestamp, you should use Timestamp#equals to equaling two different timestamp.
To check if a date is in the past: Use the Date() constructor to get the current date. Optionally set the time of the current date to midnight.
var date = new Date(); date ; //# => Fri Apr 01 2011 11:14:50 GMT+0200 (CEST) date.setDate(date.getDate() - 1); date ; //# => Thu Mar 31 2011 11:14:50 GMT+0200 (CEST)
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