8000 DATETIME type conversion problem · Issue #536 · mysqljs/mysql · GitHub
[go: up one dir, main page]

Skip to content
DATETIME type conversion problem #536
Closed
@chaoran

Description

@chaoran

The date object inserted into database, and what is retrieved from the database is different.

var mysql = require('mysql')
  , assert = require('assert');

var conn= mysql.createConnection({
  host: 'localhost',
  user: 'root',
  database: 'test'
});

conn.connect();

conn.query(
  'CREATE TABLE IF NOT EXISTS datetime_bug (id SERIAL, created_at DATETIME(3))', 
  function(err) {
    if (err) throw err;

    var date = new Date();

    conn.query('INSERT INTO datetime_bug SET ?', { 
      created_at: date
    }, function(err, result) {
      if (err) throw err;

      var id = result.insertId;

      conn.query('SELECT * FROM datetime_bug WHERE ?', { id: id }, function(err, row) {
        if (err) throw err;
        conn.end();
        assert.equal(date, row[0].created_at);
      });
    });
  }
);

This throws: AssertionError: "2013-07-11T16:28:26.218Z" == "2013-07-11T16:28:26.000Z"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0