OK. Well, you can't just "sum" two YY-MM-DD dates. You have to add an offset to a date. That's just how date arithmetic works, unless you want to figure out all the "how many days in a month" stuff yourself.
So you'll have to use the dateinterval addition method, and then do a little work to remove the milleniums.
So if your dates are in YY-MM-DD format in $datefield1 and $datefield2 ...
Code:
// get date1field from placeholder ... change placeholder name to your full element name
$date1field = '{yourtable___date1}';
// to get $date2field, which is from a calc, you'll have to redo whatever calculation you do in the date2 element again here, and assign it to $date2field
// so YOUR DATE2 CALC CODE goes here, and instead of "return" the result, assign it ...
$date2field = $whatever;
// create the first date object from the Y-m-d format
$date1 = new DateTime::CreateFromFormat('y-m-d', $date1field);
// create the PHP DateInterval string ("PxYxDxH') by exploding the second y-m-d into parts
$date2parts = explode('-', $date2field);
$date2period = "P" . $date2parts[0] . "Y" . $date2parts[1] . "M" . $date2parts[2] . "D";
// add the date interval to the date
$date1->add(new DateInterval($date2period));
// now subtract 2000 years, and then remove leading zeros from a Y (four digit) format.
// So if the two years were 55 and 65, we will have 2120, subtract 2000 and format as Y we get 0120, chop leading 0
$date1->modify('-2000 years');
$datesum = $date1->format('Y-m-d');
$datesum = ltrim($datesum, '0');
// yay, return the result
return $datesum;
I put that all in
second calc element , rename
date1 and
date2 , add the code from first calc element(date2) but still nothing. Showing not the summ in format 00-00-00.Show something like the random date in format for.ex. 23.04.2016. Code in first calc element is still there,I rename it in :
date2 , still work fine and show calculation.
// get date1field from placeholder ... change placeholder name to your full element name
$date1field = '{
radnici___stazaprije}';
//stazaprije is a field element and show quantity of years,months,days(for ex. 11-06-22)
// to get $date2field, which is from a calc, you'll have to redo whatever calculation you do in the date2 element again here, and assign it to $date2field
// so YOUR DATE2 CALC CODE goes here, and instead of "return" the result, assign it ...
//this below is from first calc element : prvidanrada is DATE element in list radnici (formatdate is 04-07-2016----fourt july)
$start_date2field = '{radnici___prvidanrada}';
if (!empty($start_date2field)) {
$now_date = new DateTime();
$start_date2field = new DateTime($start_date2field);
$since_start = $start_date2field->diff($now_date);
return $since_start->format('%y-%m-%d');
}
else {
$date2field = $whatever;
}
// create the first date object from the Y-m-d format
$date1 = new DateTime::CreateFromFormat('y-m-d', $date1field);
// create the PHP DateInterval string ("PxYxDxH') by exploding the second y-m-d into parts
$date2parts = explode('-', $date2field);
$date2period = "P" . $date2parts[0] . "Y" . $date2parts[1] . "M" . $date2parts[2] . "D";
// add the date interval to the date
$date1->add(new DateInterval($date2period));
// now subtract 2000 years, and then remove leading zeros from a Y (four digit) format.
// So if the two years were 55 and 65, we will have 2120, subtract 2000 and format as Y we get 0120, chop leading 0
$date1->modify('-2000 years');
$datesum = $date1->format('Y-m-d');
$datesum = ltrim($datesum, '0');
// yay, return the result
return $datesum;