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

275
Vistas
How can I require date format "yyyy-mm-dd" without parsing and reformatting?

I am using PostGreSql which contains date column in one of the table 2021-12-03T00:00:00.000Z. I developed API using nodejs to get the data from tables.

Below is the function I wrote to format the date and pass to the class. This works perfectly fine and I recieve 2021-12-03 as output

    formatDate(date) {
        var d = new Date(date),
            month = '' + (d.getMonth() + 1),
            day = '' + (d.getDate() + 1),
            year = d.getFullYear();
    
        if (month.length < 2) 
            month = '0' + month;
        if (day.length < 2) 
            day = '0' + day;
    
        return [year, month, day].join('-');
    }

    async getData(date){

        return {
            DataLine: await this._dateLine.getData1(d)
        }
    }

app.js

class Data extends Model {

    constructor(conn, schema) {
        super(conn, schema, "data", {
           
            Date: date(true),
            number: integer(true),  
          ...many other column
        }, true);
    }

    async getData1(date) {
        return (await this._permanent.findAll({ where: { td:date } })).map((term) => ({
            td: term.transDate,
            number: term.number,
        }));
    }
}

Is there a way to require them in the "yyyy-mm-dd" format to begin with and not parsing /reformatting as I did above as I am already getting date in format yyyy-mm-dd, my function redo that ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

One of the easiest ways to get yyyy-mm-dd is new Date().toISOString().split('T')[0]

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