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

110
Vistas
Browser Time different from MySQL Time

I'm currently working on a NodeJS-MySQL project, I'm making a controller for a table (graduates). This table has two attributes (created_at, updated_at) that receive the current date and time. The problem is: when I GET the values from this table in the Browser/Insomnia, the date is in the UTC 0 time zone (not what I want), but when i check directly on MySQL, it is in the UTC -3 (my time zone/what i want). In order to get the date values i'm using moment.js and moment-timezone.js. Some parts of my code:

var moment = require('moment');
var moment = require('moment-timezone');
moment().tz("America/Sao_Paulo").format();

setting up moment.js (setting the timezone to Sao_Paulo didn't change anything, probably i'm using it wrong)

        const result = await mysql.execute("SELECT * FROM graduates;")
        const response = {
            length: result.length,
            graduates: result.map(graduate => {
                return {
                    id: graduate.id,
                    nomeGrad: graduate.nomeGrad,
                    description: graduate.description,
                    created_at: graduate.created_at,
                    updated_at: graduate.updated_at
                }
            })
        }

Get for the table graduates (on MySQL, when I use "SELECT * FROM graduates", I get the same values, the only difference being the time)

    var dateTime = moment().tz("America/Sao_Paulo").format();
    try {
        const query = 'INSERT INTO graduates (id, nomeGrad, description, created_at, updated_at) VALUES (?,?,?,?,?)';
        const result = await mysql.execute(query, [
            req.body.id,
            req.body.nomeGrad,
            req.body.description,
            created_at = dateTime,
            updated_at = dateTime
        ]);

And this is how I Post the graduates. Now for the outputs:

    {
      "id": "43",
      "nomeGrad": "iiiiiiiiiiiiiiiiiiiiiii",
      "description": "ssssssssssssssssssssssssss",
      "created_at": "2021-10-26T23:44:10.000Z",
      "updated_at": "2021-10-26T23:44:10.000Z"
    }

The above output is from Insomnia / Browser (Time is 23:44)

# id, nomeGrad, description, created_at, updated_at
'43', 'iiiiiiiiiiiiiiiiiiiiiii', 'ssssssssssssssssssssssssss', '2021-10-26 20:44:10', '2021-10-26 20:44:10'

The above output is from directly typing "SELECT * FROM graduates" on MySQL (Time is 20:44)

Thank you for your time and patience for reading this.
about 4 years ago · Juan Pablo Isaza
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