Problem with a date calculation

Status
Not open for further replies.

Sadler

Member
Hi,

been asked to add a calculation to a list so I have added a calc element to hold/display it. I am converting the formula from a spreadsheet and what I have is this;

Code:
if ({au_data_build___Closed_Date} >0 ) { $days = date_diff({au_data_build___Closed_Date},{au_data_build___File_Opened})
 } else { $days = date_diff(date(),{au_data_build___File_Opened})
};
return (float) $days;

Basically it takes a pair of dates (open and closed) and works out what the number of days is between them, if the closed date field is empty it should use todays date rather than a zero value.
I am not getting anything back from the field.
Any clues?

Burnsy
 
Last edited:
not sure, but i think you need to convert your date before use with date_diff
I've found this example:
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days');
 
OK, fixed this one.

Code:
$OpenDate = strtotime('{au_data_build___File_Opened}');
$ClosedDate = strtotime('au_data_build___Closed_Date');
$NowDate = strtotime(date("Y-m-d"));
if ($ClosedDate == 0 ) { $DaysElapsed = $NowDate-$OpenDate;} else { $DaysElapsed = $ClosedDate-$OpenDate;}
return round($DaysElapsed / 86400);

Based on the common tasks page in the wiki which I found here:

http://fabrikar.com/forums/index.php?wiki/common-php-tasks/#dates

Burnsy
 
Cheers Hugh,

spotted that and fixed it. Sorry thought I had closed the post. Will do so now.

Burnsy
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top