Forums: [SOLVED] Conditional Formatting based on DATE - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] Conditional Formatting based on DATE Rate Topic: -----

#1 User is offline   kleanthis 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 65
  • Joined: 23-April 09
  • Gender:Male

Posted 19 February 2018 - 07:23 PM

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'

0

#2 User is offline   Pete K 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 231
  • Joined: 05-February 16

Posted 20 February 2018 - 12:54 PM

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>"; 



----------------------------------------------------------
Pete K.
Web Developer
Fayette County Public Schools | Lexington, Kentucky, USA
0

#3 User is offline   kleanthis 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 65
  • Joined: 23-April 09
  • Gender:Male

Posted 20 February 2018 - 02:47 PM

View PostPete K, on 20 February 2018 - 02:54 PM, said:

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.
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users