续订where date子句 [英] sequelize where date clause
问题描述
- 操作系统:Linux(Lubuntu)
- 语言:Javascript(Node js)
- 框架:表达js
- 数据库:mysql
- 数据"是活动"表中的日期字段
当我使用Sequelize.js运行下一条语句时
When I run the next statement 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'd have to get some records, but I get nothing
在mysql上运行我得到结果:
mysql>从活动中选择数据,其中data = '2016-10-20';
+ ------------ +
|数据|
+ ------------ +
|2016-10-20 |
|2016-10-20 |
|2016-10-20 |
|2016-10-20 |
+ ------------ +
running on mysql I get the results:
mysql> select data from activitat where data = '2016-10-20';
+------------+
| data |
+------------+
| 2016-10-20 |
| 2016-10-20 |
| 2016-10-20 |
| 2016-10-20 |
+------------+
如果我看到节点服务器的控制台.执行前条件时,显示如下:
If I see the console of the Node server. When the satement before is executed, it shows as follow:
执行(默认):选择 activitat
. codiAct
activitat
. procedencia
, activitat
. pacient
, activitat
. proces
, activitat
. prova
,激活码
. rmn
, activitat
. realitzador
,date_format( data
,'%d-%m-%Y')AS data
, tecnic
. codiTec
AS tecnic.codiTec
, tecnic
. nom
AS tecnic.nom
来自 activitat
AS activitat
左外联接 tecnics
AS tecnic
ON activitat
. realitzador
= tecnic
. codiTec
WHERE activitat
. data
=' 2016-10-19 22:00:00 '
由注册DESC订购;
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;
我的问题是:
我写了"2016-10-20"作为where子句.当我在mysql中执行操作时,它显示了我希望的结果,但是当执行sequelize时,它会通过"2016-10-19 22:00:00"(在"2016-10-20 00:两小时前")更改data子句的值:00:00"!!).为什么?
my question is:
I wrote "2016-10-20" as the where clause. When I do it in mysql it shows the results I hope, but when sequelize is executed it changes the value of data clause by "2016-10-19 22:00:00" (two hours before "2016-10-20 00:00:00"!!). Why?
我提醒您,数据"字段是日期"字段(而不是日期时间"字段)
I remeber you that "data" field is a Date field (not a DateTime field)
非常感谢您!
推荐答案
在Sequelize中定义表的字段时,我发现了一种新的字段类型.这是DATAONLY类型(而不是DATA类型).因此,字段定义如下:
I've discovered a new field type when you define the fields of the table in Sequelize. This is the DATAONLY type (instead of DATA type). So, the field definition follows as:
data:
{
type: DataTypes.DATEONLY,
validate:
{
notEmpty:
{
msg: "-> Falta data"
}
}
},
使用这种文件类型(DATAONLY)时,它仅考虑日期部分(而不考虑时间部分)
With this file type (DATAONLY) it only considers de date part (not the time part)
这篇关于续订where date子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!