Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda