Calculated Field & Custom Format

wildmanmatt

New member
Hi,

I am trying to calculate a field and then custom format it based on a date field expiry date...

I have added the following to calculated_fields_functions.php
function dadabik_get_status ($params){
// first, check if price and tax are not empty and not null
if (strtotime($params['expiry_date']) > time()) {
return 'VALID';
}
else{
return 'EXPIRED';
}
}


and the following to custom_formatting_functions.php (which I have taken from the demo application)
function dadabik_format_status($value){

if ($value === 'VALID'){
return '<img src="images/red.png">';
}
return '<img src="images/green.png">';

}

However, I think I am going to have to bulk query / edit the records in my database to populate this field (or go into each record and save each one before anything will show there)?
I also think that this field isn't going to change to red when the expiry date has passed without me going in and editing a record?

Is there any other way around this where the field will change dynamically based on the expiry date without having to edit the record first?

Thanks,

Matt

I'm not sure what I'm doing wrong
 

wildmanmatt

New member
I resolved this in a different way - I used this custom format function:

function dadabik_date_format_status($value){
if (strtotime($value) > time()) {
return '<span style="color:green"><b>'.$value.'</b></span>';
}
else{
return '<span style="color:red">'.$value.'</span>';;
}
}
 

wildmanmatt

New member
However, as I'm now using $value for my return, I'm not getting my custom date format back in the list, it's coming out in MySQL format yyyy-mm-dd

I've tried the following:
function dadabik_date_format_status($value){
$value2 = date('d/m/Y', $value);
if (strtotime($value) > time()) {
return '<span style="color:green"><b>'.$value2.'</b></span>';
}
else{
return '<span style="color:red">'.$value2.'</span>';
}
}

But that just brings back 01-01-1970 for all my dates... so, correct format, but not pulling in my correct date format. I'm not sure what I'm doing wrong?
 

eugenio

Administrator
Staff member
Hello,
I haven't read the first message but I guess is not important for the solution of the problem. You are getting the MySQL date format because you are overriding the DaDaBIK standard formatting for dates.

You could return format_date($value) or format_date_time($value), which are the functions that dadabik uses to format dates.

Best,
 
Top