Page 1 of 1

Automatically calculate date

Posted: 2013-02-24 00:25
by bescott53
I am new to PHP and appgini has proved to be excellent but I am struggling with an issue and I hoped someone could help me?

I have a date field called $LastVist. This is entered by the user. I have another date field called $NextVisit. I have a third field called $x631Status, this is an integer field with a value of 1 through to 6.

what I have been trying to do is multiply $x631Status by 30 then add this to $LastVisit to give me what the date of the $NextVisit should be but it is not displaying any date.

I have amended the tabl_dml.php file on the insert and edit lines as it showed in the support pages but still no luck. the code i found on google is below. I would be very grateful if you could help show me what I am doing wrong?

$data['NextVisit'] = strtotime($LastVisit ." + [$x631Status * 30]");

Re: Automatically calculate date

Posted: 2013-02-25 08:20
by a.gneady
You should change that to:

Code: Select all

$NextVisitTS = strtotime($data['LastVisit']) + $data['x631Status'] * 30 * 86400;
$data['NextVisit'] = date('Y-m-d', $NextVisitTS);
The above code should be in the tablename_before_insert() and tablename_before_update() hooks rather than in the tablename_dml file.

Re: Automatically calculate date

Posted: 2013-02-25 22:26
by bescott53
:D Thank you very much this works great.