Date calculation

Hey there,

Has anyone used a date calculation to provide a future date based on adding months to a user entered date (or the standard date of a record being added to the database).

I have a form where the data entered has an expiry date and at some future time will add some code or reporting to provide a list of when certain things expire.

Thanks


Sent from my iPhone using Tapatalk
 
You'd need a form submission script, onBeforeStore, which did something like this:

Code:
$thisDate = $formModel->getElementData('fab_date_test___normal_date');
$thisDate = new DateTime($thisDate);
$expirationDate = $thisDate->modify('+1 month')->format('Y-m-d H:i:s');
$formModel->updateFormData('fab_date_test___expiration_date', $expirationDate, true);

Obviously change your element names to suit.

Also note that PHP's date addition is a little weird, so if you do modify('+1 month') to 2107-01-01, you wind up with 2017-03-03. So it's adding 31 days, not a month. Yeah, I know, right.

If this matters, see this long discussion:

https://stackoverflow.com/questions/3602405/php-datetimemodify-adding-and-subtracting-months

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

Thank you.

Members online

Back
Top