Cal element using dates

keith21

Member
Hi
I want to use the cal element to determine the condition if it is red, amber or green. If greater than 2 months show red, if less than 2 months show amber and if less than or equal to 1 month show green.
I have written the code below using an online tutorial and it does not work.

$cal = '{prbi___TCDate}';
if ($cal >strtotime('2 Months'))
{
return 'Red';
}
elseif ($cal <strtotime('2 Months'))
{
return 'Amber';
}
else ($cal <=strtotime('1 Months'))
{
return 'Green';
}
 

Attachments

  • Untitled.png
    Untitled.png
    31.9 KB · Views: 127
I dont think I was very clear in my post
if prbi___Date is greater than two months from today?s date show red. any help would be wonderful. many thanks in advance
 
$cal = '{prbi___TCDate}';
$aftertwomonths = strtotime('60 day',strtotime($today))
if ($cal >$aftertwomonths)
{
return "Red";
}


Any Idea why this does not work on the cal element
 
Well, it just wouldn't wor, period, nothing to do with the calc element.

Easiest way to calculate time differences is using the DateTime object, and the diff() function.

Code:
$d1 = new DateTime();
$d2 = new DateTime('{prbi___TCDate}');
$interval = $d2->diff($d1);
return (int)$interval->format('%m') > 2 ? 'red' : '';

-- hugh
 
Sorry I am not sure where to add the code, I am using the date element --> under advance --> php allow date function.

Thanks once again
Keith
 
Oh, well, no, that's totally the wrong place. That function is where you define "blackout" dates for the popup calendar. And your original post shows the code in a calc element?

OK, so when you talk about changing colors, are you talking about in a list display, or a form/details display?

I assumed you meant you were using the List setting that allows you to use an element's value as the CSS class for the row, which lets you do things setting the background color of the list to different colors depending on dates.

-- hugh
 
What I want to achieve is when a user selects a date, in another field on the form it works out the logic. If date from today is more than 2 months show as red in that field. So we two fields one the date and other the status.
I only used the cal element as I thought it?s the best way to do calculations, if any other way to best achieve this I be happy to use that.

Thanks once again
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top