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.

date string parse bug

See original GitHub issue
const mysql = require('mysql2/promise');

mysql.createConnection({
    host: '127.0.0.1',
    user: 'app',
    password: 'password',
    database: 'app',
}).then((conn) => {
    conn.query('SELECT DATE(?) AS `date_field`', ['2019-08-30']).then(([result]) => {
        console.log(result);
    }).then(() => {
        return conn.close();
    })
});

Date object show 2019-08-29 but date string is 2019-08-30

node version: v10.17.0 mysql2 version: 2.0.2

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
tugrulcommented, Dec 19, 2019

dateStrings: true connection option able to use to workaround

0reactions
sidorarescommented, Dec 27, 2019

But I tried to evaluate new Date(‘2019-08-30’); is getting correct value 2019-08-30T00:00:00.000Z

the server returns “2019-08-30” string to us, and this library tries it’s best to convert that into Date object

if you don’t pass tz, it’s using “local” timezone - https://github.com/sidorares/node-mysql2/blob/a0ea513b0d4929e6ee61639a09f38a85ac01f7fa/lib/packets/packet.js#L611

> new Date(2019, 7, 30)
2019-08-29T14:00:00.000Z
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error parsing date string with `new Date` - javascript
Your date string (whatever it is "31-08-2016" ) isn't in a format recognized by the Date constructor. So you ended up with a...
Read more >
Error parsing date string when trying to copy one
Solved: I've put in a place an automatic rule that where a date custom field takes (start date) the value of another date...
Read more >
Parse error: Invalid digit in the date string
This error indicates that the Destination IMAP system rejected an item because of an invalid date. When creating items at the Destination using ......
Read more >
Error Parsing String with String to Date&Time
I've just updated to Knime v.4.5 and I got a parse error with a workflow that I ... I get the message “Execute...
Read more >
Date.parse() - JavaScript - MDN Web Docs
The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or...
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