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

278
Views
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 answers
Answer question

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 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!