Is there an easy way of taking a olain JavaScript Date
(e.g. today) and going back X days?
So, for example, if I want to calculate the date 5 days before today.
Therefore, you can add or subtract days as easy as adding or minus the number of days in Excel. 1. Select a blank cell you will place the calculating result, type the formula =A2+10, and press the Enter key. Note: For subtracting 10 days from the date, please use this formula =A2–10.
Show activity on this post. let yesterday=new Date(new Date(). getTime() - (1 * 24 * 60 * 60 * 1000)); let last3days=new Date(new Date(). getTime() - (3 * 24 * 60 * 60 * 1000));
You can subtract a day from a python date using the timedelta object. You need to create a timedelta object with the amount of time you want to subtract. Then subtract it from the date.
Try something like this:
var d = new Date(); d.setDate(d.getDate()-5);
Note that this modifies the date object and returns the time value of the updated date.
var d = new Date(); document.write('Today is: ' + d.toLocaleString()); d.setDate(d.getDate() - 5); document.write('<br>5 days ago was: ' + d.toLocaleString());
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