I am trying to compare the time from a timestamp with the current time.

I currently have the following line:

$this->db->where('period_end >', $time);

But this compares 1995-04-08 13:00:00 against 10:43:44

What i want to compare is 13:00:00 against 10:43:44 and ignore the date completely.

Any ideas?

有帮助吗?

解决方案

You can compare the time part from datatime field by using DATE_FORMAT,Also using this approach you need to pass third parameter as FALSE to avoid addition of backticks by active record

$this->db->where("DATE_FORMAT(period_end,'%H:%i:%s') >", $time,FALSE);

Small demo

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top