How can I filter date-time columns by dates in Propel 1.6?

twigmac picture twigmac · Mar 11, 2013 · Viewed 7.6k times · Source

I would like to filter results as in

$searchDate = "2013-03-01";

$query->usePublicationQuery()
            ->filterByPublishedAt($searchDate)
            ->endUse();

However, the problem is, that the values in this column contain also the time, i.e. they're actually timestamps (e.g. "2013-03-01 08:27:12") and I'm not allowed to change that in the schema. So how can I possibly match the pure date ignoring the time? The above query only matches entries with the time 2013-03-01 00:00:00. But I want all entries with 2013-03-01 as date, regardless of the time.

Answer

twigmac picture twigmac · Mar 12, 2013

I've figured out this solution and it works:

->filterByPublishedAt(array("min" => $searchDate." 00:00:00", "max" => $searchDate." 23:59:59"))