I have to get the timestamp of last Friday, but I am not sure how can I get timestamp using weekday. Can someone please help?
What I trying to get is difference between last Friday and Today.
var now = new Date();
var time = now.getTime();
var fridayTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 30, 00);
var timeDiff = time - fridayTime;
I know I have not written the correct code for "fridayTime", but not sure what is the correct code.
To get last week's date, use the Date() constructor to create a new date, passing it the year, month and the day of the month - 7 to get the date of a week ago. Copied! function getLastWeeksDate() { const now = new Date(); return new Date(now. getFullYear(), now.
var today = new Date(); var startDay = 0; var weekStart = new Date(today. getDate() - (7 + today. getDay() - startDay) % 7); var weekEnd = new Date(today. getDate() + (7 - today.
Use the setDate() method to get the previous day of a date, e.g. date. setDate(date. getDate() - 1) .
const t = new Date().getDate() + (6 - new Date().getDay() - 1) - 7 ;
const lastFriday = new Date();
lastFriday.setDate(t);
console.log(lastFriday);
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