question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sequelize ignores milliseconds part of DATETIME in MySQL

See original GitHub issue

I’m using MySQL database with some columns of type DATETIME(3) (datetime with precision 3). Also in the entity model I have defined type as DATE(3). But after I set property of instance to time with millisecond part (e.g. entity.openedAt: “2015-08-29T08:39:08.12345Z”), sequelize generates SQL query, that truncates the millisecond part (…openedAt=‘2015-08-29 08:39:08’…).

MySQL 5.6.4 and up expands fractional seconds support for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
sobotklpcommented, Feb 28, 2016

In order to use millisecond-aware DATETIME columns, you’ll have to use type: DataTypes.DATE(3)

1reaction
mfbx9da4commented, Feb 27, 2016

+1 also having this problem using sequelize 3.19.2 when should this be working?

models.scheduled_matches.update(
    {saved_timeout_time: "2016-02-27T16:49:45.458Z"},
    {where:{running_match_id: 139}})

produces

UPDATE `scheduled_matches` 
SET `saved_timeout_time`='2016-02-27 16:49:45',`updatedAt`='2016-02-27 17:16:06' 
WHERE `running_match_id` = 139
Read more comments on GitHub >

github_iconTop Results From Across the Web

Timestamp with a millisecond precision: How to save them in ...
You need to be at MySQL version 5.6.4 or later to declare columns with fractional-second time datatypes. Not sure you have the right...
Read more >
Dialect-Specific Things - Sequelize
The underlying connector library used by Sequelize for MySQL is the mysql2 ... that has been idle for longer than the specified duration...
Read more >
A Guide to Handling Date and Time for Full Stack JavaScript ...
Learn how to work with date and time values in JavaScript. ... Date.now(); // number of milliseconds since the Unix Epoch new Date()....
Read more >
datetime comparison ignoring few milliseconds-sql-server
So depending on where exactly the rounding occurs, timestamps that differ by up to three milliseconds may be considered equal. Mureinik 281020. score:7....
Read more >
Sequelize - how to format the date for date types values
The DATE type that converts to the SQL DATETIME format. The two types use the ISO standard to format the values they send...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found