Automatically calculate date

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
bescott53

Automatically calculate date

Post by bescott53 » 2013-02-24 00:25

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]");

User avatar
a.gneady
Site Admin
Posts: 1287
Joined: 2012-09-27 14:46
Contact:

Re: Automatically calculate date

Post by a.gneady » 2013-02-25 08:20

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.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

bescott53

Re: Automatically calculate date

Post by bescott53 » 2013-02-25 22:26

:D Thank you very much this works great.

Post Reply