Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
"OnThisDay" feature with Nextjs using getServerSideProps with Date.now() at runtime

I'm trying to implement a "OnThisDay" Wikipedia style feature with Nextjs, showing an event that happened on that day. For this I have a function that looks like this:

const list = [{"dateOfDeath": "2000-01-01", "name": "X"},{"dateOfDeath": "2000-01-02", "name": "Y"]

const dateObj = new Date();
const currentDay =
  ('0' + (dateObj.getMonth() + 1)).slice(-2) +
  '-' +
  ('0' + dateObj.getDate()).slice(-2);

export default function GetToday() {
  return list.filter(
    (person) => person.dateOfDeath.slice(5) === currentDay
  );
}

I'm then getting this via getStaticProps:

export const getStaticProps: GetStaticProps = async () => {
  const today = GetToday();
  return {
    props: {
      today
    },
    revalidate: 10
  };
};

This all works fine and well, however it seems that the Date object is created once at build time, so the page is stuck with whatever date the site was build on. I purposfully set revalidate to 10s trying to solve this, which didn't work. I also tried using getServerSideProps instead but that didn't change anything either. I'm deploying the site with Docker, using pretty much the Docker template of the Nextjs repo.

Does someone know a way, that a new Date object is created at runtime?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!