Reputation: 1118
I am creating project using nodejs and mysql. I have unique kind of problem. I am fetching the data from table.All the results coming from db is correct except datetime.In my db date is stored like: 2016-11-02 11:16:10
and the type of table field is timestamp
. When i query the data am getting date like this format
Tue Nov 01 2016 10:19:17 GMT+0530 (India Standard Time) } ]
I want to get the data which is stored in db like 2016-11-02 11:16:10
.
Here is the Query am using:
var sql = "SELECT * FROM PEN_WFM_TXN_Details Where customerID = ?";
req.getConnection(function(err, connection) {
var query = connection.query(sql, [data[0].customer_uuid], function(err, rows) {
console.log("klkkkkkkkkkkkkkkkkkkkkkkkkk")
console.log(rows)
for(i=0; i<data.length; i++){
for(j=0; j<rows.length; j++){
if(data[i].uuid == rows[j].topology_tag_uuid){
transactions.push({
topology_uuid:rows[j].topology_tag_uuid,
status:exports.getTransactionStatusByCode(rows[j].status),
creationTime:rows[j].modifiedTime,
name:data[i].name,
txnId:rows[j].txnID
})
}
}
}
res.send(transactions)
})
})
Upvotes: 1
Views: 729
Reputation: 1118
Simple Solution is set the dateStrings settings in mysql connection like:
app.use(connection(mysql,{
dateStrings :'date',
database : "PEN_GUI",
multipleStatements : true
},'request
'));
Upvotes: 1
Reputation: 1563
You are getting a JavaScript date time object. You can get the day/mongh/year/minuts .... and format it manually here is a link the Date Reference
Upvotes: 1