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

255
Vistas
Validate date using Joi without convert it to utc format

Is there is a way to validate a date using @joi/date but without changing the date to UTC format.

I'm trying to validate the date before I send it to the DB

What I tried

const Joi = require('joi').extend(require('@joi/date'));
...
    const schema = Joi.object({
        f_title: Joi.string().required(),
        date: Joi.date().format('YYYY-MM-DD').required(),
    });

But the problem is that 2000-05-15 will always be converted to 2000-05-15T21:00:00.000Z and the DB will raise an incorrect date value.

Thanks : )

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

0

A possible workaround is to initiate a new date object from the date the user has sent, and next, you can get the full year, month, and day... also if you use this way, you will get the date in this format no matter what browser the user is using.

const Joi = require('joi').extend(require('@joi/date'));
...
    const schema = Joi.object({
        f_title: Joi.string().required(),
        dateVarFromUser: Joi.date().format('YYYY-MM-DD').required(),
    });
###
// Rest of your code
###

Before sending the request to the DB, add the following

const datObj = new Date(dateVarFromUser);
dateVarFromUser = datObj.getFullYear() + '-' + (datObj.getMonth()+1) + '-' + datObj.getDate()

###
// Then, you could send it to the SQL handler/function
###


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