0

I am using CakePHP2.1.3, and I have two dates. The first is a start date set through an add model form and I want to keep that one. The second I want to be generated from a variable based on a previous choice. I pulled the variable out, so that's done. Now I need to find out how to calculate the end date based on the start date and this variable.

For example, I would want the end time on an hourlong class to be $start_time +1hour. This way I can set these for each event and the user doesn't have to think about how long this class is.

I tried using mktime and that doesn't work. So I wondered if CakePHP has a helper out there somewhere for modifying dates, or if CakeTime could do it, though that hasn't worked for me so far.

tereško
  • 58,060
  • 25
  • 98
  • 150
user1230790
  • 73
  • 1
  • 10

1 Answers1

0

You can create a virtual field in your model if you need it to use frequently. Or you can make a new field in the find query.

$this->Model->find('all', array('conditions' => array(....), 'fields' => array(...., 'DATE_ADD('YOUR FIELD', INTERVAL 1 HOUR) AS END_TIME')));

OR you can define it in your model like:

$virtualFields = array('END_TIME' => 'DATE_ADD(NOW(), INTERVAL 2 HOUR)');
Arun Jain
  • 5,476
  • 2
  • 31
  • 52