This topic is locked
[SOLVED]

 Add 120 days to a date field

11/2/2015 4:17:36 PM
PHPRunner General questions
S
stec5345 author

I have a field named CAQHAttestDate, I have another field in the same table named CAQHReAttestdate. How can I get the CAQHReAttestDate to populate automatically with CAQHAttestDate +120 days either after record entered or immediately after the first date is entered? Any help would be appreciated.
Steve

Sergey Kornilov admin 11/2/2015

I recommend to check this:

http://xlinesoft.com/blog/2014/11/12/datetime-handling-in-web-applications/
Most likely you will need to do that in events like BeforeAdd or BeforeEdit so check 'PHP' section.

romaldus 11/3/2015

This is very easy.

In before record added (add page) or before record update (edit page) event, use the following code <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78181&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

$values["CAQHReAttestDate"] = date("Y-m-d", ($values["CAQHAttestDate"]) + strtotime('+120 days'));

S
stec5345 author 11/3/2015

Thank You!!!!



This is very easy.

In before record added (add page) or before record update (edit page) event, use the following code <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78198&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

$values["CAQHReAttestDate"] = date("Y-m-d", ($values["CAQHAttestDate"]) + strtotime('+120 days'));


S
stec5345 author 11/3/2015

I marked this as solved a little too hastily. When I put the code in place to add 120 days, it does produce a date but it seems all the values it is posting is 120 days from Now() only and not 120 days from CAQHAttestDate. I did add the code to both the ADD page Before record processed and to the Edit page Before record Updated. Could this have caused a problem? I didn't think so. I wanted it to be on both so the CAQHAttestDate could be edited or added if not in the original record. I also wanted it to be added when and if the CAQHAttestDate was available at time of adding the new record.

romaldus 11/4/2015

Sorry, the correct syntax is :

$values["CAQHReAttestDate"] = date("Y-m-d", strtotime($values["CAQHAttestDate"].'+30 days'));


S
stec5345 author 11/4/2015

That worked. Thank You.



Sorry, the correct syntax is :

$values["CAQHReAttestDate"] = date("Y-m-d", strtotime($values["CAQHAttestDate"].'+30 days'));