This topic is locked

Date value custom formatting

7/6/2015 5:21:38 PM
PHPRunner General questions
M
mmaner author

I am applying formatting changes based on the value in View as > Custom. I want to make the entire cell background a specific color, not just the background of the text. Is there a way to do that? Additionally is there a way to apply the date/time format %d/%m/%y - %H:%i to the value a well? Thanks

if( strtotime($value) < strtotime) {

$background="#cc0000"; $color="#ffffff";

}

else if( strtotime($value) == strtotime) {

$background="#cc0000"; $color="#ffffff";

}

else if( strtotime($value) < strtotime('+1 day') ) {

$background="#cc0000"; $color="#ffffff";

}

else if( strtotime($value) < strtotime('+2 day') ) {

$background="#cc0000"; $color="#ffffff";

}

else if( strtotime($value) < strtotime('+3 day') ) {

$background="#ff6600"; $color="#ffffff";

}

else if( strtotime($value) < strtotime('+4 day') ) {

$background="#ff6600"; $color="#ffffff";

}

else if( strtotime($value) < strtotime('+5 day') ) {

$background="#ffff33"; $color="#000000";

}

else if( strtotime($value) < strtotime('+6 day') ) {

$background="#ffff33"; $color="#000000";

}

else if( strtotime($value) > strtotime('+6 day') ) {

$background="#009900"; $color="#ffffff";

}

$value="<span style='background: " . $background . ";color: " . $color . "'>".$value."</span>";
M
mmaner author 7/7/2015

I had already looked at both of those actually, but thanks for the info. When I try to move from span style formatting to style formatting I get no formatting at all. I'm thinking its a syntax issue. The same is true with the date format, I just dont understand how to combine the style and date formatting against the value.

HJB 7/7/2015

... for inspiration purposes ex http://www.asprunner.com/forums/topic/22924-compare-date-fields-on-the-fly/
$aktiv = $values["aktivdatum"] ; // Date 1

$deaktiv = $values["deaktiv"] ; // Date 2
$aktivDatum = strtotime($aktiv) ;

$deaktivDatum = strtotime($deaktiv) ;
if ( ($deaktivDatum != null) and ( $aktivDatum >= $deaktivDatum ) )

{

$message = "Falscher Datumsbereich: Deaktiv-Datum ist kleiner als Aktiv-Datum!" ;

return false ;

}
return true;

Admin 7/7/2015

In your last line of code instead of $value you need to use something like this:

date("Y-m-d H:i:s",strtotime($value))


You can see all PHP date formatting options at http://php.net/manual/en/function.date.php

M
mmaner author 7/7/2015



In your last line of code instead of $value you need to use something like this:

date("Y-m-d H:i:s",strtotime($value))


You can see all PHP date formatting options at http://php.net/manual/en/function.date.php


I was able to get the Date format to display correctly by using the following as the last line of the above quoted code...

$value="<span style='background-color: " . $background . ";color: " . $color . "'>".date("m/d/Y H:i:s",strtotime($value))."</span>";


I havent been able to get the cell background color set. When I change span style to style or nothing I get no formatting at all. Thanks for the help.

HJB 7/7/2015

I was able to get the Date format to display correctly by using the following as the last line of the above quoted code...

$value="<span style='background-color: " . $background . ";color: " . $color . "'>".date("m/d/Y H:i:s",strtotime($value))."</span>";



unquote excerpt of your previous lines
Quote excerpt out of http://xlinesoft.com/blog/2011/01/03/tutorial_conditional_formatting/

6.$value="<span style="color: &quot; . $color . &quot;;">$value</span>";

unquote excerpt
Can you see the code discrepancies?

M
mmaner author 7/7/2015



Can you see the code discrepancies?


I can see the discrepencies, but when I make the code changes I get no formatting at all. That's why I am asking here. I am sure I'm missing something, but I can't figure out what it is.
If I backup and remove all the unnecessary formatting, only focusing on the cell background color, the line should looks like this I think.

$value="<style='background-color: " . $background ."'>"$value;


Whne I use this code instead of 'span style='background-color:' I get no formatting at all.