This topic is locked
[SOLVED]

 Conditional Formatting based on DATE

2/19/2018 2:23:15 PM
ASPRunner.NET General questions
K
kleanthis author

Hello to all.

I add the following code into view as > custom option. The field is a date format.

string color;

DateTime rightNow = DateTime.Now;

if (value > rightNow) {

color="black";

}else {

color="red";

}

value="<span style='color: " + color + "'>" + value.ToString() + "</span>";


I get this error
include\CustomExpressions.cs(24,30): error CS1955: Non-invocable member 'System.DateTime.Now' cannot be used like a method.

include\CustomExpressions.cs(25,5): error CS0019: Operator '>' cannot be applied to operands of type 'runnerDotNet.XVar' and 'System.DateTime'

Pete K 2/20/2018

Try converting value to a DateTime variable before doing the comparison:

string color;

DateTime rightNow = DateTime.Now;

DateTime MyValue = DateTime.Parse(value);

if (MyValue> rightNow) {

color="black";

}else {

color="red";

}

value="<span style='color: " + color + "'>" + value.ToString() + "</span>";
K
kleanthis author 2/20/2018



Try converting value to a DateTime variable before doing the comparison:

string color;

DateTime rightNow = DateTime.Now;

DateTime MyValue = DateTime.Parse(value);

if (MyValue> rightNow) {

color="black";

}else {

color="red";

}

value="<span style='color: " + color + "'>" + value.ToString() + "</span>";



That works just fine.

Thanks a lot.