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 acode : $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. Thanks anyway.
Uhm... What? Do you want the final calculation to be an actual date, or just adding the separate numbers together? If the latter, you'll have to split the string up and add each pair, before outputting the new values.
I want just adding the separate numbers together. I've got a good solution in excel , but (Y-m-d) is in 3 column,and solved with excel formulas.Thanks.
For what it's worth, in PHP you could do something like this: $date1 = explode('-','29-04-10'); // you can use variables instead of the actual dates, of course $date2 = explode('-','13-05-16'); echo $total = join('-',[$date1[0]+$date2[0],$date1[1]+$date2[1],$date1[2]+$date2[2]]); PHP: The above will output this: 42-9-26 Code (markup): And if you want leading zeros, change the $total from the above to this: echo $total = join('-',[sprintf('%02d', $date1[0]+$date2[0]),sprintf('%02d', $date1[1]+$date2[1]),sprintf('%02d', $date1[2]+$date2[2])]); PHP: Which will output this: 42-09-26 Code (markup):
How to use variables.If I could understand , this is two solutions.Can i change '29-04-10' and '13-05-16' in first solutions with yourtable___yourdate , or with Y-m-d. I tried write that in my fourth field (calc element). but nothing happenedThird field is only field and number is in text format.Second field is calc element with code.Fourth field is also could be a calc element with code you give me,but nothing.How you get the result.
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 =newDateTime(); $start_date =newDateTime($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!
Why don't you do your calculations with the time() function? Edit: I guess it doesn't matter if it's a non-existing date. How about: $finalval = ((int)gmdate('d', $alinuxtime) + (int)gmdate('d', $anotherlinuxtime)).'-'.((int)gmdate('m', $alinuxtime) + (int)gmdate('m', $anotherlinuxtime)).'-'.((int)gmdate('Y', $alinuxtime) + (int)gmdate('Y', $anotherlinuxtime));
Yedort thanks , but i think ; useful solution is PoPSiCLe solution,but I am beginner , and don't know set the variables,and must be taken into consideration and resolution of the CALC field.Just adding the separate numbers together in the fourth calc field.All that is in column in database table!Never mind , thanks! PS. I must put a column_name instead of these 29-04-10 and 13-05-16.