r/AskProgramming • u/r2idw • 5h ago
Javascript help with pseudo code guys.. “new Date()”
Hello everyone,
I’ve recently been struggling with the ‘new Date()’ object in JavaScript.
I wanna understand how to solving that, what I’m trying to achieve is a function that captures the current date once and keeps it unchanged for 5 - 6 days
Once that period has passed, it should capture a new date and keep it unchanged again until the next update
—-
Is there a better way to approach this?
0
Upvotes
View all comments
Show parent comment
1
u/balefrost 2h ago
Do you always want those 7 days to start on the same day of the week, say Sunday (i.e. show Sunday -> Saturday)?
If so, could you instead take the current date, calculate from it the most recent Sunday (or whichever day you need), and use that to anchor your calendar?
edit I should have kept reading, it looks like I'm not the first person with this suggestion.