- Operating System: Linux (Lubuntu)
- Programming Language: Javascript (Node js)
- Framework: express js
- Database: mysql
- "data" represents a Date field from the "activitat" table
Upon running this query using Sequelize.js
models.TblActivitat.findAll(
{
attributes:
[
'codiAct', 'procedencia', 'pacient', 'proces', 'prova', 'rmn', 'realitzador',
[Sequelize.fn('date_format', Sequelize.col('data'), '%d-%m-%Y'), 'data']
],
include: models.TblTecnics,
where: {"data": '2016-10-20' }, //dataAAAAMMDD
order: "registre DESC"
}).then(function(tblActTec){
...
});
... I am not receiving any records despite expecting some
Querying on mysql yields the following results:
mysql> select data from activitat where data = '2016-10-20';
+------------+
| data |
+------------+
| 2016-10-20 |
| 2016-10-20 |
| 2016-10-20 |
| 2016-10-20 |
+------------+
When checking the Node server console, the query execution appears as follows:
Executing (default): SELECT activitat
.codiAct
, activitat
.procedencia
, activitat
.pacient
, activitat
.proces
, activitat
.prova
, activitat
.rmn
, activitat
.realitzador
, date_format(data
, '%d-%m-%Y') AS data
, tecnic
.codiTec
AS tecnic.codiTec
, tecnic
.nom
AS tecnic.nom
FROM activitat
AS activitat
LEFT OUTER JOIN tecnics
AS tecnic
ON activitat
.realitzador
= tecnic
.codiTec
WHERE activitat
.data
= '2016-10-19 22:00:00'
ORDER BY registre DESC;
My question is:
I specified "2016-10-20" in the where clause. While it retrieves the correct results in mysql, when executed using sequelize, the value of the data clause gets altered to "2016-10-19 22:00:00" (two hours before "2016-10-20 00:00:00"!!). Why does this happen?
It should be noted that the "data" field is strictly a Date field and not a DateTime field
Thank you very much for your assistance!