I have a problem retrieving the dates in my Rest API.
I insert a data and the datetime is automatically filled in my BD. for example.
2017-09-27T23:16:46.000Z
this value that is generated automatically and I can see it with mysql workbench.
But when I recover with my API it is a basic query like this:
select * from inv;
Returns 2017-09-27T21:16:46.000Z
with two hours less than the value of the database.
What could be the problem?
I insert two images so that you can see the table and the response of the API.
Greetings and thanks.
EDIT:
This is the code I use to launch the request to the DB:
function getInvTop(req, res) {
if (connection)
{
connection.query('SELECT * FROM invjuan WHERE attrName = "sensor2" ORDER BY recvTime DESC LIMIT 15', function(err, rows) {
if(err)
{
throw err;
console.log('Error al Conectar' + error);
}
else
{
res.status(200).json(rows);
}
});
}
}
For the answer for now I only call the method from Postman.
As a client I am using Angular4
, I do not know if the correct thing is to format the date from this one.
If I launch this query it gives me the following error:
SELECT recvTimeTs, CONVERT_TZ('recvTime','GMT','MET'), fiwareServicePath, entityId, entityType, attrName, attrType, attrValue, attrMd FROM iof.invjuan WHERE attrName = "sensor2" ORDER BY recvTime DESC LIMIT 15;