Click to See Complete Forum and Search --> : Null date field's giving me a headache!


NatuScape
02-06-2003, 01:54 PM
Hi all!

I'm trying to use some code to format a date field from a database in red background when it's older than today. This bit of code I put together works wonderfully when the field has data, but not so when the field is null. I can't get it to work and I'm sure it's a silly thing I'm missing... Help!?

CODE:

date1 = Date()
date2 = FP_FieldVal(fp_rs,"DueDate")
Ldate2 = Len(date2)

If Len(date2) = 0 then
Response.Write("")
Else
If DateDiff("d", date1, date2) < 0 then
Response.Write("bgcolor=#CC0000")
Else
Response.Write("")
End If
End If


Thanks a bunch!

Natalia

Ribeyed
02-06-2003, 04:04 PM
hi,
can you post more of the code. The sql statement the recordset etc.

NatuScape
02-07-2003, 07:16 AM
Hi Ribeyed and Dave,

Thanks so much for your replies! Unfortunately, the solution Dave suggested didn't work. I also tried IsDate(date2) and that didn't work either... What am I missing???

As for the SQL statements and such, I'm (please don't hit me) using FP2002 to create the database linking, but in this case I don't think that's what's hurting it, but rather my unimaginative self!!

Thanks again and post any more ideas if you have them!

Natalia

Ribeyed
02-07-2003, 07:58 AM
hi,
try something like this, you will get the idea:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
date1 = date()
'date2 = FP_FieldVal(fp_rs,"DueDate")
date2 = "21/12/2004"


if date2 = "" or date2 = "NULL" then

bgcolor = "#FFFFFF"
else

if date1 < date2 then
bgcolor = "#FF0000"

end if
end if


%><table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="19%"><%=date1%></td>
<td width="81%" bgcolor="<%=bgcolor%>"><%=date2%></td>
</tr>
</table>
<%
if date1 < date2 then
response.write "date 1 is less then date 2"
else
response.write "date 1 is greater than date 2"
end if

%>
</body>
</html>