This topic is locked
[SOLVED]

 Conditional Formatting with DateTime

8/21/2018 12:16:44 PM
ASPRunner.NET General questions
R
rl74martinez author

Hello,
I have a table with a datetime field called AcceptDate. I am trying to set the row style color to red when the AcceptDate is within 30 days from today's date. This is what I have tried under Events List page: After record processed
if data["AcceptDate"] < datetime.now(-30)

row["rowstyle"]="style"='background: red'";
I am getting a error with the syntax. Any help is appreciated!
Thanks,

Robert

admin 8/21/2018

Your IF condition misses parenthesis around it. Please refer to examples in the manual:

https://xlinesoft.com/asprunnernet/docs/conditional_formatting.htm

R
rlmartinez 8/22/2018

Thank you. I added the parenthesis and now I'm getting the following error message:
Non-invocable member 'System.DateTime.Now' cannot be used like a method.
Any thoughts? Any help is appreciated. Thanks.

A
Arkie 8/22/2018

I always had a bad time with date stuff, so I learned to do the calcs in a query; such as

===========

SELECT

[key],

acceptdate,

date() - acceptdate as apples

FROM Table1

=============

This merely gives you the number of days difference as a variable called apples.
Then in an event on your List page in After Record Processed, use something like:

======================================

if (data["apples"] < 30)

record["css"] = "background:red;";

=====================================

~Joe

admin 8/22/2018

datetime.now(-30) is meaningless. See this for inspiration:

https://stackoverflow.com/questions/1665941/c-sharp-30-days-from-todays-date
The best option is to make sure your code works outside of ASPRunner.NET and then you can use it in one of events. You cannot just guess the syntax.

R
rlmartinez 8/30/2018

Thanks Joe. I went with your approach and ended up using DateDiff.
Here is the query I used:
SELECT

datediff(month, getdate(), acceptdate) AS apples,

key

FROM table
Then in the event on the List Page: After Record Processed I used this:
if (data["apples"] <1)

row["rowstyle"]="style='background: red'";