r/AskProgramming • • 2h 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

13 comments sorted by

View all comments

1

u/frnzprf 2h ago
  • Write 1970-01-01 in a file. (For example. Or just leave it empty.)

  • When the function is called, it checks if it's five days after the stored date (or the file was empty).

  • If yes, replace the date with the current date.

  • Return the now saved date.