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.

datetime fields returned as date when time is 00:00:00

See original GitHub issue

Setting a DATETIME field with the value 2019-10-01 00:00:00 Then retrieve the data using the execute command: const [result] = connection.execute('SELECT * FROM my_table', [])

result will equal to ‘2019-10-01’ instead of ‘2019-10-01 00:00:00’ although it’s a DATETIME field and not merely a DATE

note that when using query the behavior is as expected

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lirancrcommented, Oct 28, 2019

any update on this ? let me know if there’s something i do to help out

1reaction
lirancrcommented, Oct 21, 2019

Sure here is a standalone snippet

    //running with node 10.16.0 using mysql2 ^1.7.0

    const mysql = require('mysql2/promise');

    async function main() {
    let db = await mysql.createConnection({
        host: 'localhost',
        port: '3306',
        user: 'root',
        password: 'root'
    });
    await db.query("SET time_zone='+00:00'");
    await db.query('DROP DATABASE IF EXISTS test_db');
    await db.query('CREATE DATABASE IF NOT EXISTS test_db');
    await db.close();

    db = await mysql.createConnection({
        host: 'localhost',
        port: '3306',
        user: 'root',
        password: 'root',
        database: 'test_db',
        dateStrings: true,
        timezone: '+00:00'
    });

    await db.query('CREATE TABLE IF NOT EXISTS mytbl (id INT AUTO_INCREMENT, created DATETIME NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB');
    await db.execute('INSERT INTO mytbl (created) VALUES (?)',['2019-10-01 00:00:00']);
    let [result] = await db.execute('SELECT * FROM mytbl', []);
    console.log('execute result',result[0]);
    [result] = await db.query('SELECT * FROM mytbl', []);
    console.log('query result',result[0]);
    
    }

    main();

scratches.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does MySql format datetime microseconds as .000000?
The database is free to return date and datetime values however it likes. The creators of MySQL chose the most general format for...
Read more >
datetime => how to have complete date with 00:00:00.000
Hi,. i work with sql server 2005 and i 'm a beginner. I have a table with a column datetime. in this table...
Read more >
8.4: Data Type Formatting Functions - PostgreSQL
The PostgreSQL formatting functions provide a powerful set of tools for converting various data types (date/time, integer, floating point, ...
Read more >
How to convert DateTime format from 00:00:00 to 23:59:59
I have converted a Date into DateTime format, and it is returning me the hour format in 00:00:00 but I want it to...
Read more >
Data Lake Analytics:Date and time functions - Alibaba Cloud
EXTRACT extracts and returns the value of a specified datetime field from a datetime or interval value expression. Syntax: EXTRACT(unit FROM ...
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