This topic is locked

date question

7/4/2007 3:49:19 AM
PHPRunner General questions
D
diaster author

super noob here. can anyone tell me how to take the date from field "date" and perform a calculation on it so the field "anniversary date" is a date 365 days later. I need this new date to sort for records one year old or older.
php runner is way cool, i am using trial version but am buying it on payday, their support is awesome

J
Jane 7/4/2007

ted,
you can do it using Before record added and Before record updated events on the Events tab/ Here is a sample code:

// split FirstDate to array

$arr = db2time($values["FirstDate"]);

// construct time

$t = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);

// construct new date

$values["AnniversaryDate"] = date("Y-m-d",$t + 606024*365);



where FirstDate and AnniversaryDate are your actual field names.

D
diaster author 7/4/2007

ted,

you can do it using Before record added and Before record updated events on the Events tab/ Here is a sample code:
where FirstDate and AnniversaryDate are your actual field names.



Thank you very much, just bought the product 5 minutes ago, much impressed with product, support and knowlegable forum!!!

D
diaster author 7/4/2007

I am getting this message back
Error type 8

Error description Undefined offset: 3

URL demo.asprunner.net/thecollinscompany_sbcglobal_net/Project1/_Entertainers_add.php?

Error file C:\UserAccounts\www\thecollinscompany_sbcglobal_net\Project1_20070704040224\include\_Entertainers_events.php

Error line 15

SQL query insert into `_Entertainers`

J
Jane 7/5/2007

Ted,
looks like you have NULL values in your field.

Add some checking,i.e.

if($values["FirstDate"])

{

// split FirstDate to array

$arr = db2time($values["FirstDate"]);

// construct time

$t = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);

// construct new date

$values["AnniversaryDate"] = date("Y-m-d",$t + 606024*365);

}