Update the ending-date by selecting a starting date

QuestionsUpdate the ending-date by selecting a starting date
Michael Sheppard asked 4 weeks ago

I would like to add x-years to a Start Date selection and have it automatically update the End Date field based on an Interval with a call-back function.

To further explain:

I have four columns.

Skill ID, Start Date, Interval and End Date.

When adding a new record, I select the Skill ID and it runs the call-back function and populates the Interval-years. This works perfectly. I then select the “Start Date” from a date-picker. The next-thing I would like is to be able to update the “End Date” field, based the “Start Date” plus the number of years in the Interval column – with an update or callback function.

I tried the callback function – but it does not appear to work.

Any thoughts?



4 Answers
Abu Ghufran Staff answered 2 weeks ago


You need to adjust end_date value in callback, e.g.

// set 3rd param to true – means don’t stop after callback and continue grid insert/update.
$e[“on_update”] = array(“update_client”, null, true);

function update_client($data)

$interval = $data[“params”][“interval”]; // assuming interval is numeric and in dayss
$data[“params”][“end_date”] = date(“Y-m-d”, strtotime(“+$interval days”, $data[“params”][“start_date”]));


This will make update query with end_date field as well. Code is just to give idea.

If it does not work as expected, you can share grid code for review.

Abu Ghufran - Dev Team
Grid 4 PHP Framework
Mike answered 2 weeks ago

Thanks for the feedback. The problem I have is I need the “ADD RECORD” form to display the END DATE so the person entering the data sees the date change. I tried the direct update first and that works – but we need feedback for the person entering the data.





Abu Ghufran Staff answered 2 weeks ago

Ok, thats doable as well. You can connect a JS function with onblur event on start_date and interval fields.

And inside that callback, fetch values of both source fields and set value in end_date. For help refer this code demo in faq: https://www.gridphp.com/faqs/#80


Some JS date calculation would be required, you can check https://stackoverflow.com/questions/563406/add-days-to-javascript-date

Abu Ghufran - Dev Team
Grid 4 PHP Framework
Mike answered 2 weeks ago

That’s put me on the right track – thank you! I was trying to use the same method as the “On Change” and it wasn’t working. The “OnBlur” seems to do what I need – I just have to get the date-calc to work now.





Your Answer

16 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?