Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if ... then statement

Status
Not open for further replies.

s4dadmin

Programmer
Apr 27, 2003
107
0
0
US
I am trying to make N/A print if there is no date. If there is a date the date will print, but if there is no date then N/A will not print. I am using mysql and the date format is 2003-10-10 07:50:21
Here is the code

<%If dtLastPostDate <> &quot;&quot; Then%>
<font size=&quot;<%=frm_dscp_fontsz%>&quot; face=&quot;<%=frm_dscp_fontfm%>&quot; color=&quot;<%=frm_dscp_fontcl%>&quot;><%=fncFmtDate(dtLastPostDate, &quot;%d %b %Y at %h:%N %P&quot;)%><br>
by <a href=&quot;javascript:popUp('popup_profile.asp?id=<%=rsAuthor(&quot;MemberID&quot;)%>','popUp','width=375,height=250,scrollbars=yes')&quot;><%=rsAuthor(&quot;lastpostmember&quot;)%></a></font>
<%Else%>
<center><font size=&quot;<%=frm_dscp_fontsz%>&quot; face=&quot;<%=frm_dscp_fontfm%>&quot; color=&quot;<%=frm_dscp_fontcl%>&quot;>N/A</font></center>
<%End IF%>
 
When there is no date, is the field in database actually null? If so, try:

if isNull(dtLastPostDate) then
 
I have tried both ways and it still does not work. The field is not null it would all zeros if there is no date
 
Try to use isDate function.

Dim MyDate, YourDate, NoDate, MyCheck
MyDate = &quot;October 19, 1962&quot;
YourDate = #10/19/62#
NoDate = &quot;Hello&quot;
MyCheck = IsDate(MyDate) ' Returns True.
MyCheck = IsDate(YourDate) ' Returns True.
MyCheck = IsDate(NoDate) ' Returns False.

Like

If (isDate(dtLastPostDate)) Then
....
 
if that also does not work:

if Cstr(dtLastPostDate)=&quot;0000-00-00&quot; then
response.write &quot;N/A&quot;
end if

Known is handfull, Unknown is worldfull
 
Or you could approach this from the database side when retrieving your recordset:
Code:
&quot;SELECT Field1, ISNULL(DateField,'N/A') AS myDate FROM myTable&quot;

This is, of course, provided that the date field in your database either contains a valid date or is null. Not sure if the syntax between T-SQL and mySQL are the same, but this should give you an idea. Then, you do not have to worry about the if...then statement in ASP, all the work is done on the db. Hope this helps.

-----------------------------------------------------------------------------------------------------
&quot;If you can't explain something to a six-year-old, you really don't understand it yourself.&quot;
-- Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top