Cakephp 时间之间的条件或时间列不是时间
Cakephp Conditions Between Times or if time column is not a time
我有一个 table 如果行在特定时间之间,我需要从中提取记录。但有些时候是 UFN(直至另行通知)。如果结束时间是字符串而不是时间,我怎样才能让 cakephp 忽略 'end' 时间?如果用户想要显示 UFN,我强制他们将 'end time' 留空会不会更容易?
提前致谢
编辑:
我正在从事的项目很敏感,所以我不能 post 任何实际代码,但这里有一个例子。
$this->Event->find('all', array(
'conditions' => array(
'Event.active_start <' => date('Y-m-d H:i:s', strtotime($date . " +31 minutes")),
'Event.active_stop >' => $date,
'Event.id >' => $id,
),
'order' => 'Event.active_start',
'group' => 'Event.id'
)
);
Event.active_start 始终是日期时间,但 Event.active_stop 可以是日期时间或字符串,通常是 'UFN'.
此查询未提取任何字符串行。
- 将
'Event.active_stop'
设置为DATETIME字段,允许为空。
- 保存前检查日期时间格式,如果没有取消设置($string)
- 查找(回调)后如果
active_stop
为空字段,return字符串'UFN'
我有一个 table 如果行在特定时间之间,我需要从中提取记录。但有些时候是 UFN(直至另行通知)。如果结束时间是字符串而不是时间,我怎样才能让 cakephp 忽略 'end' 时间?如果用户想要显示 UFN,我强制他们将 'end time' 留空会不会更容易?
提前致谢
编辑: 我正在从事的项目很敏感,所以我不能 post 任何实际代码,但这里有一个例子。
$this->Event->find('all', array(
'conditions' => array(
'Event.active_start <' => date('Y-m-d H:i:s', strtotime($date . " +31 minutes")),
'Event.active_stop >' => $date,
'Event.id >' => $id,
),
'order' => 'Event.active_start',
'group' => 'Event.id'
)
);
Event.active_start 始终是日期时间,但 Event.active_stop 可以是日期时间或字符串,通常是 'UFN'.
此查询未提取任何字符串行。
- 将
'Event.active_stop'
设置为DATETIME字段,允许为空。 - 保存前检查日期时间格式,如果没有取消设置($string)
- 查找(回调)后如果
active_stop
为空字段,return字符串'UFN'