This topic is locked

Add days to date

12/26/2008 2:41:33 PM
PHPRunner General questions
P
phpwalker author

i have the following fields:
autoContactInt (integer)

setAutoContact (enum Y/N)

nextContactDate (varchar 15) - in PHPR, edit as "date" ... drop down boxes with date picker
here is what i want to do...
on edit:

if setAutoContact == Y,

nextContactDate = now() + autoContactInt
currently i have tried...
in the Before Record Updated i added the following custom code:
if ($values['setAutoContact'] == 'Y'){
$followup = mktime(0, 0, 0, date("m"), date("d")+10, date("y"));

$values['nextContact'] = $followup;

}
note: the +10 is just for debugging rigt now... want to change this to $values[]'autoContactInt'] once this is working....
however, after editing a record i am getting the following ouput aftering refreshing the edit screen:
day drop down: 13

month drop down: empty

year drop down: 12
and in the list view: 0012/00/13 (the list view is set to "view as" short date
as a sidenote i also tried this code:

this works!!!
if ($values['setAutoContact'] == 'Y'){

$values['nextContact'] = date("Y-m-d",strtotime("+3

day"));

}

return true;
Changed to this:

This doesn't work!!!
if ($values['setAutoContact'] == 'Y'){

$days = $values['autoContactInt'];

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

}

return true;
and it does NOT work... results in the following date: 1969/12/31
Help?

P
phpwalker author 12/27/2008

Wanted to post this fix in case anyone else did the same bone-head thing I did...
The following code from above works now

if ($values['setAutoContact'] == 'Y'){

$days = $values['autoContactInt'];

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

}

return true;


FIX: The nextContact date MUST be a date field in mySQL. (my bad)
Once the date field is correctly set as date in mySQL, it will also ensure that your dates will sort correctly...