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

295
Vistas
Timestamp being sent in my route response, but my table in the database does not show the timestamp

exports.up = (knex, Promise) => knex.schema.createTable('cohorts', (table) => {
  table.increments('id')
  .primary();
  table.string('name', 'varchar(6)')
  .notNullable();
  table.string('type', 'varchar(3)')
  .notNullable();
  table.date('q1_start_date')
  .notNullable();
  table.date('q2_start_date')
  .notNullable();
  table.date('q3_start_date')
  .notNullable();
  table.date('q4_start_date')
  .notNullable();
  table.date('graduation_date')
  .notNullable();
  table.integer('campus_id')
  .notNullable()
  .references('id')
  .inTable('campuses')
  .onDelete('CASCADE');
  table.timestamps(true, true);
});

exports.down = (knex, Promise) => knex.schema.dropTable('cohorts');

I am using postgresql to make my database in which I use date in my migrations when I check my table in the database it is stored in the date format; however when writing my routes in bookshelf.js those dates come with the timestamp.

Here is my response with the timestamp

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

when node-postgres driver reads date type of column from database, it automatically converts it to Date object of javascript, which has actually date and time.

You can configure pg driver to return dates in string format if you like to with this package https://github.com/brianc/node-pg-types

Type id of date type is:

mikaelle=# select typname, oid, typarray from pg_type where 
pg_type.typname = 'date' order by oid;
 typname | oid  | typarray 
---------+------+----------
 date    | 1082 |     1182
(1 row)

And code to set parsing for the type can be done like this:

var types = require('pg').types
types.setTypeParser(1082, function(val) {
  return val; // just pass the string
})
over 4 years ago · Santiago Trujillo 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