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

151
Views
date in moment.js does not change when submit new transaction still save last date until refresh server

I am using moment.js to format date and save it in DB

Schema code

const Schema = new mongoose.Schema({
    transactionTime: {
        type: Date,
        default: moment().toDate(),
    },

front code

<td>{moment(transaction.transactionTime).format('MMMM Do YYYY, h:mm:ss a')}</td>

but when I submit a transaction the date is not updated for real-time I send it I must refresh the server to update the date

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When using moment().toDate() as the default, the default value is set to the date and time when you started the application and stays constant. What you want to do is to rather specify a function that returns the current date, which would result in the function being executed at each insertion, thus getting the actual current time:

const Schema = new mongoose.Schema({
    transactionTime: {
        type: Date,
        default: () => moment().toDate(),
    },
...
about 4 years ago · Juan Pablo Isaza Report
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!