Hi,
I have 2 fields (date1 and date2), and I am trying to calculate the number of days between these 2 fields. If date1 is empty field, I will get the current date.
Example: date1=Today date(eg. 15/12/2012), date2=User input (eg. 10/12/2012), difference=5
Below are my code which works if I put it in "Before record added" and "Before record updated":
----------------------------------------------------------
if ($values["date1"]=="" || $values["date1"]==NULL){
$date1 = time();
$date2 = strtotime($values["date2"]);
$date3 = $date1-$date2;
$values["difference"]= floor($date3/(606024));
}
-------------------------------------------------
However, I am now trying to increment the difference by 1 as each day goes by automatically after the intial record is created. Need someone advice on this.
Taking from the above example, on 15/12/2012, user created a record with date2=10/12/2012. The difference will be 5, however the following day, the difference will be automatically become 6, etc.
I tried putting the below code under "After successful login" but it seems not working.
------------------------------------------------
mysql_connect ("localhost", "username", "password") or die (mysql_error());
mysql_select_db ("database") or die (mysql_error());
$result=mysql_query ("Select from table_name");
$row=mysql_fetch_array($result);
if ($row["date1"]=="" || $row["date1"]==NULL){
$date1 = time();
$date2 = strtotime($row["date2"]);
$date3 = $date1-$date2;
$row["difference"]= floor($date3/(6060*24));
}
------------------------------------------
Thanks in advance for the help.