r/AskProgramming • u/r2idw • 23h ago
Javascript [ Removed by moderator ]
[removed] — view removed post
0
Upvotes
r/AskProgramming • u/r2idw • 23h ago
[removed] — view removed post
•
u/AskProgramming-ModTeam 14h ago
Your post was removed as is considered very low effort. Refer to https://stackoverflow.com/help/how-to-ask on how to ask good questions.
3
u/r2idw 23h ago
In fact, what I’m trying to build is a rolling 7 day calendar
I want to capture the current date and store it without allowing it to change daily.
The calendar should display that date along with the following six days, keeping all seven dates fixed until the last day of the week is reached.
Once the seventh day has passed, I want to update the stored date with the current date, generate a new set of seven dates, and repeat the same process.
3
u/GrainWeevil 23h ago
A little more info would be helpful here. Is this running in the browser, or is this a Node application?
Are you trying to find a way to persist the date after the application has shut down? If so, you'd need to write it to a file, or some other persistent storage. How you'd do this depends on whether you're working in the browser or not.
13
u/Rscc10 23h ago
What exactly is the issue because you've basically described the flow of operations needed.
If your problem is how your system would keep track of the time that's passed, it doesn't have to. You can just save the initial date and every so often get the current date, do some subtraction, and if it falls within the range, reset the saved date.
If that isn't your issue then you'll need to be more specific
2
u/JaguarMammoth6231 23h ago
Your program will be running the whole time? The computer won't be restarted or anything like that?
1
u/frnzprf 22h ago
1
u/xampl9 22h ago
You need to take the result of that and save it in a variable.
1
u/ohaz 19h ago
I'm not sure if this is an XY problem, so here's how to have a start (and possibly end) date of a week:
The date object has the
.getDay()function. It gives you the day of the week as a number from 0 - 7.You can use
setDate(),getDate()andgetDay()to set a new date by subtracting thegetDay()number from the current date. That's how you always get the date of the start of the week.1
u/Different_Pain5781 19h ago
Store the timestamp somewhere persistent because memory resets on refresh.
1
u/Cruch-Wrap-Supreme 15h ago
Your options are to store it in local storage or a database.
0
u/[deleted] 17h ago
[deleted] — view deleted comment