node.js - MYSQL returns full datetime string on SELECT query when column type is DATE -
i have hard time finding answer question after many researches on google, terms not seem accurate enough yield correct answers question.
i have database storing information on customers: first name, last name, birthdate etc.
the problem specific birthdate column. type set date , every results, shows date in phpmyadmin, when use select in script retrieve rows, birthdate column returned if datetime type except when value 0000-00-00.
i using node-mysql retrieve results mysql table in app. built module on top of node-mysql shorten required code pooling, databasepool function comes from. here sample node.js code behaviour shown:
property: { get: function(id, callback) { mysql.databasepool(function() { this.query('select birthdate icm_contact icm_contact_id = ? limit 1', [id], function(err, rows, fields) { console.log(rows[0]); callback(null, icm.contact.revive(rows[0])); }) }); } }
for given date: 2015-08-11 return { birthdate: tue aug 11 2015 00:00:00 gmt-0400 (edt) }
, date 0000-00-00 return { birthdate: '0000-00-00' }
expected.
i don't have clue why phpmyadmin displays date correctly no matter what, when query script, won't return date correctly.
i have tried following: datetime mysql select date
property: { get: function(id, callback) { mysql.databasepool(function() { this.query('select date(birthdate) icm_contact icm_contact_id = ? limit 1', [id], function(err, rows, fields) { console.log(rows[0]); callback(null, icm.contact.revive(rows[0])); }) }); } }
but still date returned datetime.
did try this?
property: { get: function(id, callback) { mysql.databasepool(function() { this.query('select date_format(birthdate,\'%m-%d-%y\') icm_contact icm_contact_id = ? limit 1', [id], function(err, rows, fields) { console.log(rows[0]); callback(null, icm.contact.revive(rows[0])); }) }); } }
Comments
Post a Comment