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 type and 0000-01-01

See original GitHub issue

Hi,

I have a date field in MySQL table with 0000-01-01 default value. In MySQL it stores correctly, but when I execute a select query I get ‘1900-01-01T00:00:00.000Z’ value. screen shot 2018-10-09 at 10 41 30 am

I think this a bug, because 0000 != 1900. I’m using this field for user birthday and age calculating. So when I’m trying to calculate a user age I get 118 years old. I handle zero values in my app and I think I should not handle 1900 value.

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nanom1tcommented, Oct 10, 2018

It works with dateStrings: true. Thank you!

1reaction
sidorarescommented, Oct 10, 2018

Works as expected when I pass dateStrings: true ( sorry in my first comment I said it should be “false”. Meaning of that flag is “don’t try to construct js Date and just return the string as it’s stored”

[ TextRow { birthday: '0000-01-01' },
  TextRow { birthday: '0000-01-01' },
  TextRow { birthday: '0000-01-01' },
  TextRow { birthday: '0000-01-01' } ]

When dateStrings is not set resulting date is built here: https://github.com/sidorares/node-mysql2/blob/0da580e52c3ae37832c8fde49dddd56fb88aa52b/lib/packets/packet.js#L541

return new Date(y, m - 1, d); - in your case y is 0, m is 1 and d is 1. I’d say 1900-01-01T00:00:00.000Z is also expected in this case, that’s the way js Date constructor interprets years

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data types (date and numeric formats) - Oracle Help Center
There are three data types in Eloqua: Text, Numeric, and Date/Time. Each data type defines the format of information that can be entered...
Read more >
UniPay Gateway Documentation
Type : Entity Status: Active ... Code; Create Date; Fulfillment Center FK ... Values of the bit mask in decimal format (e.g. 00000101)....
Read more >
Numbers and dates - JavaScript - MDN Web Docs - Mozilla
A string representing a date in the following form: "Month day, year hours:minutes:seconds." For example, let Xmas95 = new Date("December 25, ...
Read more >
Permit Application Status - Bloomington, MN
Application Type: Utility. Application Status: Finaled ... 1 1/2" C2 METER S/N 89388286 READING 00000101. Application Date: 02/02/2021. Issued Date:.
Read more >
Format numbers as dates or times - Microsoft Support
To quickly enter the current date in your worksheet, select any empty cell, and then press CTRL+; (semicolon), and then press ENTER, if...
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