Re: datetime difference in days(created and action_date column)
convert to unix timestamp using TimeHelper::fromString() , substract, and you'll get duration in miliseconds.. erm.. ever heard of this question before.. On Jan 12, 3:18 pm, aku Gaban wrote: > Dear friends > I would like to ask how to implement calculation at view.ctp and > controllers to get difference between created > and action date column and to be appear at duration column. > i found resource in php but i dont know how to implement it into > cakephp > hope can help me > > thank you in advance -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: datetime difference in days(created and action_date column)
You could try googling for it. http://lmgtfy.com/?q=date+difference+php Also, in the future, let's try and keep this group CakePHP related. While I don't mind helping out with PHP-only questions here and there, that's not really the purpose of this group :) Anyway, try date_diff. Like AD said, there's many ways to do this. That's one. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: datetime difference in days(created and action_date column)
thank you ad for your reply. but this seem not appear what i want. i have no idea.not good in php too On Jan 12, 5:29 pm, AD7six wrote: > On Jan 12, 8:18 am, aku Gaban wrote: > > > Dear friends > > I would like to ask how to implement calculation at view.ctp and > > controllers to get difference between created > > and action date column and to be appear at duration column. > > i found resource in php > > Is it a secret hidden resource only for the eyes of the elite? > > There are lots of ways to do that - the simplest of which is to do it > exactly the same way you'd do it with php since (gasp) CakePHP is > written in php. > > AD -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: datetime difference in days(created and action_date column)
On Jan 12, 8:18 am, aku Gaban wrote: > Dear friends > I would like to ask how to implement calculation at view.ctp and > controllers to get difference between created > and action date column and to be appear at duration column. > i found resource in php Is it a secret hidden resource only for the eyes of the elite? There are lots of ways to do that - the simplest of which is to do it exactly the same way you'd do it with php since (gasp) CakePHP is written in php. AD -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
datetime difference in days(created and action_date column)
Dear friends I would like to ask how to implement calculation at view.ctp and controllers to get difference between created and action date column and to be appear at duration column. i found resource in php but i dont know how to implement it into cakephp hope can help me thank you in advance -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Datetime difference
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 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: > > 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Datetime difference
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: 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Datetime difference
You could calculate the time difference on the fly with mysql TIMEDIFF function [http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timediff] instead of store it in the db And this [http://www.gidnetwork.com/b-16.html] may help to store the time difference. Céryl escribió: > Hej all! > > Since my good advice just ago, I got to another bottleneck. > > I have a form in which the user selects two times (a start- and an end- > time). The form works perfectly and the times get stored in the table > as hh:mm:ss. > > However, I have a 3th row in the database that must hold the elapsed > time between the two form-inputted times. I want the computer to > calculate this. I figured I must do this in in the controller, I can > of course even do after the $this->Model->save() action with a > saveField, just before the redirect. > > However, I cannot seem to find a good example of making that function. > I'm not sure how i get my timestamp back from the form, if they are > simply substractable and how to store it back in the table. > > If it makes matters easier, elapsed time can be stored as an integer > holding seconds between times in the table, I can probably calculate > those back in elapsed minutes/hours in a later view of the table. > > Any idea's or links to examples of working with Timestamps? It always > boggles me! > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Datetime difference
Hej all! Since my good advice just ago, I got to another bottleneck. I have a form in which the user selects two times (a start- and an end- time). The form works perfectly and the times get stored in the table as hh:mm:ss. However, I have a 3th row in the database that must hold the elapsed time between the two form-inputted times. I want the computer to calculate this. I figured I must do this in in the controller, I can of course even do after the $this->Model->save() action with a saveField, just before the redirect. However, I cannot seem to find a good example of making that function. I'm not sure how i get my timestamp back from the form, if they are simply substractable and how to store it back in the table. If it makes matters easier, elapsed time can be stored as an integer holding seconds between times in the table, I can probably calculate those back in elapsed minutes/hours in a later view of the table. Any idea's or links to examples of working with Timestamps? It always boggles me! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---