I'm having trouble finding a date format that is common to Node.js, knex, and MySQL (via the Bookshelf).
I installed a table with the Knex schema builder:
knex.schema.createTableIfNotExists("examples", function (table) {
...
table.dateTime("some_datetime");
})
In MySQL, a column with a type is created DATETIME.
I have a model of a bookshelf that represents this (leaving all the boilerplate material here), and I'm trying to use the built-in Date.now()as a value:
exampleModel.save({
some_datetime: Date.now()
})
With debugging enabled in Knex, I see that the request is actually trying to insert an era timestamp with milliseconds ("..." for short):
{ ...
bindings: [ 1485644012453, ... ],
sql: 'update `examples` set `some_datetime` = ? where `id` = ?' }
But this is not true, since MySQL expects what you will useFROM_UNIXTIME in this case, so the final date in the database is, of course, good ol ' 0000-00-00 00:00:00.
, ?
- , ?
- , - , ,
Date.now()? - - ?
. , DATETIME Knex, Date.now() Node, DATETIME MySQL, .
, : , - , / . , .