This topic is locked
[SOLVED]

 Change cell color based on age of date

1/18/2010 9:26:35 AM
ASPRunnerPro General questions
S
stealthwifi author

I have a filed called Valid as of Date. It will be a date manually entered showing the age of a document.

I would like the view to be custom so that if the valued entered is two years old the cell color will be red.
I have the below code but I am unsure of how to set it up so it checks for it to be two years old?

str = "<table width=100% bgcolor="

if strValue<=Now() then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str
C
clig 1/18/2010



I have a filed called Valid as of Date. It will be a date manually entered showing the age of a document.

I would like the view to be custom so that if the valued entered is two years old the cell color will be red.
I have the below code but I am unsure of how to set it up so it checks for it to be two years old?

str = "<table width=100% bgcolor="

if strValue<=Now() then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str



here's a sample based on a string - for a date do a datediff on the year in the case of older than 2 years
str = "<table width=100% bgcolor="

if strValue= "Major" then

str = str & "red"

else

if strValue= "MAC" then

str = str & "#B6A2C5"

else

if strValue= "Minor" then

str = str & "yellow"

else

str = "<table width=100%"

end if

end if

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str

C
clig 1/18/2010



I have a filed called Valid as of Date. It will be a date manually entered showing the age of a document.

I would like the view to be custom so that if the valued entered is two years old the cell color will be red.
I have the below code but I am unsure of how to set it up so it checks for it to be two years old?

str = "<table width=100% bgcolor="

if strValue<=Now() then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str



sample filter for date = 2 years ago (DATEDIFF(year, dbo.NTSS_Tickets.DateEntered, GETDATE()) = 2) - adjust for language the sample is MSSQL

S
stealthwifi author 1/18/2010



sample filter for date = 2 years ago (DATEDIFF(year, dbo.NTSS_Tickets.DateEntered, GETDATE()) = 2) - adjust for language the sample is MSSQL


Doesn't work for me, please check my syntax I think I made a mistake somewhere:

When loading i get:
Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'year'

/include/aspfunctions.asp, line 2184

str = "<table width=100% bgcolor="

if strValue<=(DATEDIFF(year, dbo.Allison.ValidAsOfDate, GETDATE()) = 2) then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str


Also tried the two below which removed the error but doesnt color the cell correctly (or at all)

str = "<table width=100% bgcolor="

if strValue<="(DATEDIFF(year, dbo.Allison.ValidAsOfDate, GETDATE()) = 2)" then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str


str = "<table width=100% bgcolor="

if strValue<="'(DATEDIFF(year, dbo.Allison.ValidAsOfDate, GETDATE()) = 2)'" then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str
S
stealthwifi author 1/18/2010

I solved it, the correct way is below:

str = "<table width=100% bgcolor="

if (DATEDIFF("yyyy", strValue, NOW()) > 2) then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str
C
clig 1/25/2010



I solved it, the correct way is below:

str = "<table width=100% bgcolor="

if (DATEDIFF("yyyy", strValue, NOW()) > 2) then

str = str & "red"

end if

str = str & "><tr><td>" & strValue & "</td></tr></table>"

strValue = str



cool should have been more explicit when I mentioned "adjust for language" or I could have been less lazy and given you a VBScript sample - good to hear you got it.