Yeah, I already solved it with PHP code... The thing I was hanging on
was that the data returned on the form to the controller is not a
DateTime but an array. So when I want to do my $this->data->save()
function, I was unable to calculate the time since all examples use
the DateTimeformat.

I did a workaround by first saving everything in the form to the
database (apart from the time-difference), then re-extracting the two
time-values (which when reextracted are now of the datetime format)
and do the calculations in PHP with tweaked examples given above, and
adding the calculated value back into the correct row.

Far from optimal, but it's a workaround to get everything up and
running, I'll refactor it later when I figured out what array the
automagic DateTime-formhelper returns.

Thanks!



On 19 mei, 17:11, Stu <[email protected]> wrote:
> Just note that Gabriel's answer is probably the cleanest way to do it,
> but If you would prefer using a PHP function:
>
> http://www.codingforums.com/archive/index.php/t-140522.html
>
> Cancer10's code worked great for me:
>
> <?php
> function datediff($date1,$date2,$format='d'){
> $difference = abs(strtotime($date2) - strtotime($date1));
> switch (strtolower($format)){
> case 'd':
> $days = round((($difference/60)/60)/24,0);
> break;
> case 'm':
> $days = round(((($difference/60)/60)/24)/30,0);
> break;
> case 'y':
> $days = round(((($difference/60)/60)/24)/365,0);
> break;
>
> }
>
> return $days;
>
> }
>
> echo datediff('2008-8-1','2007-8-30','D') . ' Days';
> echo datediff('2008-8-1','2007-8-30','m') . ' Months';
> echo datediff('2008-8-1','2007-8-30','y') . ' Years';
> ?>
>
> Plus you could tweak this code a bit if you would like seconds,
> minutes, hours or weeks.  Thing is, this will not work out to well for
> leap years.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to