nipo Posted January 25, 2017 Share Posted January 25, 2017 Hi ! I have a litle problem. I have on my form four field. In first I have a birthdays in format d-m-Y(12-03-1994). Second field calculatig age from birthday until now ,formated Y-m-d (29-04-10 for example), and have a code : $start_date = '{yourtable___yourdate}';if (!empty($start_date)) { $now_date = new DateTime(); $start_date = new DateTime($start_date); $since_start = $start_date->diff($now_date); return $since_start->format('%y-%m-%d');}else { return "no data";} and work fine . PROBLEM IS : In third field have another age in format Y-m-d for example 13-05-16 , and want summ with second field. (29-04-10 + 13-05-16 = 42-09-26) The summ of calculating 42-09-26 (Y-m-d) must be displayed in fourth field ,but how. Quote Link to comment Share on other sites More sharing options...
nipo Posted January 27, 2017 Author Share Posted January 27, 2017 Is anybody at homeeeee Quote Link to comment Share on other sites More sharing options...
Barand Posted January 27, 2017 Share Posted January 27, 2017 No one that understands the sanity in adding two dates. Quote Link to comment Share on other sites More sharing options...
nipo Posted January 29, 2017 Author Share Posted January 29, 2017 I have a first field on form with job beginning in date format d-m-Y (27-03-1997 for example).Second calc field is with code and can calculate a length of sevice from beginning (27-03-1997) until today.Calc field show me result in Y-m-d format(19-03-29) and work fine.Here is the code: $start_date = '{yourtable___yourdate}';if (!empty($start_date)) {$now_date = new DateTime();$start_date = new DateTime($start_date);$since_start = $start_date->diff($now_date);return $since_start->format('%y-%m-%d');}else {return "no data";} Now, I have another length of service (03-08-02 for example) in same form, which is done before 1997. ,and wrote in simple third field in text format(Y-m-d). I want in fourth calc field on form get the summ of those two length of service. Exactly : 24-00-01 must be result (19-03-29 + 03-08-02).One month is 30 days.Form is on Joomla 2.5 , made with form builder. Thanks for help! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted January 29, 2017 Share Posted January 29, 2017 (edited) This still doesn't make much sense, and there's no PHP function which could do that for you. The DateTime::diff() method calculates the actual number of days, months and years between two dates. If you want to “add” another interval using your own logic (“one month is 30 days”), you have to do that yourself. That is, you must add the days of both intervals, divide the result by 30, then add the months etc. Like I said, there is no PHP function for this kind of logic. Edited January 29, 2017 by Jacques1 Quote Link to comment Share on other sites More sharing options...
nipo Posted January 30, 2017 Author Share Posted January 30, 2017 Perhaps , but perhaps the last counting to be understood not as a time or date , but as simply data, which for months has a limit of 12, and for days 30.Perhaps Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted January 31, 2017 Share Posted January 31, 2017 Perhaps you should talk less and do more. You know how division with remainder works, right? Do it then. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.