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

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

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