LogixMaster
LogixMaster

Reputation: 586

CakePHP- DateTime and php's date()

I have a datetime field type in one table inside the db, which represent the start date and time of an event.

I want to execute something as follows:

$taken_timeslots = $this->Schedule->find('all', array(
  'conditions' => array(date('Y-m-d 00:00:00', strtotime('start_at')) => $today)
));

where start_at is my database field, and $today is

$today = date('Y-m-d 00:00:00', $day_timestamp);

Basically I want to fetch all records which fall under 'today' . I would prefer if I use cake's find() method rather than query(), but will take anything into consideration, especially if a good answer is given! Thanks a heaps!

Upvotes: 0

Views: 1174

Answers (1)

skywalker
skywalker

Reputation: 826

Here is how I would do it, since your $today is the date you are looking for. First you must specify your field in the db:

$taken_timeslots = $this->Schedule->find('all', array(
   'conditions' => array('Date(Schedule.start_at)' => $today)
));

EDIT: I copied your code, there was one ) where there shouldn't be one :) Try now.

And this can be any day you want like this:

$today = date('Y-m-d 00:00:00', strtotime('29 September 2013'));

Upvotes: 2

Related Questions