Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda