calc date field

merlino68

Member
I have a date field (data field) and a weeks field, in a calc field I would like to add to the date the number of the weeks and find the new date.
you can do this?

thanks
 
Code:
// build a date object from your date placeholder
$myDate = new DateTime('{yourtable___yourdate}');
// add your week placeholder
$myDate->modify('+{yourtable___yourweeks} week');
// return formatted date
return $myDate->format('Y-m-d');

Replace the element names with your full element names.

You would probably want to add some error checking to make sure both placeholders have a value, but that's the basics of date manipulation.

-- hugh
 
It works perfectly, great component and excellent service.
Where can I find more examples of calculations with dates?
thank you
 
That's just standard PHP using the DateTime class. The only Fabrik specific part is using the {yourtable___yourelement} placeholders to get your initial values.

Pretty much every conceivable date calculation question has been answered on StackOverflow. Just google your question ("how do I subtract months from a date in php"), look at the StackOverflow answers, and find one that use DateTime (not older ones that use strtotime).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top