This topic is locked
[SOLVED]

Compare date to current date, and change background if greater than current date

6/4/2024 3:09:28 PM
ASPRunner.NET General questions
M
MSchell author

If the value for transition_start_date is greater than today, I want to change the background. Log error now does not exist, how do I compare a date to current date, and highlight the field.

if (data["Transition_Start_Date"] > now())
{
record["css"]+="background:yellow;";
}
else
{
record["css"]+="background:white;";
}

D
DealerModulesDevClub member 6/5/2024

In Events / List page: After record processed:
Try
IF($data["Transition_Start_Date"] > now())
{
$record["Transition_Start_Date_css"]='background:yellow;';
}
ELSE
{
$record["Transition_Start_Date_css"]='background:white;';
}

This is for php, not sure if it is the same syntax for .net

Paul

M
MSchell author 6/5/2024

It didn't like the $. the issue appears to be the now()

D
DealerModulesDevClub member 6/5/2024

Don't know .net syntax so I found this in the ASPRunner manual.

Maybe it will help with syntax. (Hope this helps).
Here is a direct link to the manual.

Changing the background of a cell

You may change the background of the cell to yellow, based on its value. As you are working with the table structure here, you will have to use the events.

Proceed to the Events screen in the ASPRunnerPro and select the After record processed event for the List page of the Products table.

The code is similar to the previous examples:

img alt

if data("Profitability")<0 then

record("Profitability_css") = record("Profitability_css") & "background:yellow"

end if

conditional_formatting3
Highlighting an entire row of a table

You can use the same condition check in the After record processed event - change the code to set the entire row yellow. Your code may look like this:

if data("Profitability")<0 then

record("css")="background:yellow"

end if

And if you want to change the background color of all rows regardless of the condition, you can simply delete the condition in this event:

record("css")="background:yellow"

Sergey Kornilov admin 6/6/2024

If you need to compare two values as Dates you need to convert them to a Date data type first.

Here is where you need to start:
https://stackoverflow.com/questions/919244/converting-a-string-to-datetime

Convert data["Transition_Start_Date"] to String object first then convert it to Date, then compare it with another Date object.

M
MSchell author 6/10/2024

Solved, I settled on the code below, converting the date is what resolved it!

if datetime.parse(data("Transition_Start_Date").tostring()) > system.datetime.now() then
record("css")="background:yellow"
else
record("css")="background:white"
End if