0

I am running mysql from node using mysql

I have observed a strange behavior where data from 6th July is not recognized.

The following is the code:

var mysql = require('mysql');

var dbconn = mysql.createConnection({
    host: 'xx.xxx.xxx.xxx',
    user: 'xxxxxx',
    password: 'xxxxxx',
    database: 'xxxxxx'
        });
connection.connect(function (err) {
    if (err) {
        console.log(err);
    }
    queryString = "select max(createdon) max_date from gate";


DBSelect(dbconn, queryString, [], function (success, msgObj) {
console.log(' ');

    console.log('// dbconn.config.dateStrings', dbconn.config.dateStrings);
    console.log('msgObj', msgObj.results[0].max_date);

    dbconn.config.dateStrings = true;
    console.log(' ');

    DBSelect(dbconn, queryString, [], function (success, msgObj) {
        console.log('// dbconn.config.dateStrings', dbconn.config.dateStrings);
        console.log('msgObj', msgObj.results[0].max_date);
    })

})


});


function DBSelect(dbObject, queryString, values, callback) {
    dbObject.query({
        sql: queryString,
        timeout: 40000, // 40s
    },
        values,
        function (error, results, fields) {

            if (error !== null) {
                callback(false, error);
            }
            else {
                callback(true, {
                    results: results,
                    fields: fields
                });
            }
        }
    )
}

and this is the output i get

// dbconn.config.dateStrings false
msgObj 2018-07-05T13:48:58.000Z

// dbconn.config.dateStrings true
msgObj 2018-07-05 19:18:58

But when i execute the same query from Navicat (mysql client similar to MySQL Workbench) i get proper response

enter image description here

Unable to identify the issue, please suggest.

Lakshman Pilaka
  • 1,803
  • 2
  • 24
  • 48

0 Answers0