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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Format Question

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hey all,

I have been using a date format with LCID and a format code I was shown by this forum a while back which works fine when there is a date in the field.

The problem I had was when the date field was Null, I would get an error. So I tried and if then Else statement which is where I was still tearing my hair out until I just swapped the code around and reversed the argument.

Can anybody tell me why this code DOES Work:
Code:
 <%
Dim Mymonth
Mymonth = (Men.Fields.Item("DatePaid").Value) 
%>
<%
If Mymonth <>"" Then
Response.Write Day(Mymonth)&"-"&MonthName(Month(Mymonth),true)&"-"&Right(Year(Mymonth),2)
Else
response.Write("Not Paid")
End If
 %>
And this code DOES NOT work
Code:
 <%
Dim Mymonth
Mymonth = (Men.Fields.Item("DatePaid").Value) 
%>
<%
If Mymonth = "" Then
response.Write("Not Paid")
Else
Response.Write Day(Mymonth)&"-"&MonthName(Month(Mymonth),true)&"-"&Right(Year(Mymonth),2)
End If
 %>

It is the same argument, but just asking the opposite question of the date field.

Thoughts?

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
DB Nulls react oddly in comparison statements in VBScript. I agree that they should both be failing, however I have found in many situations that having a Null in your If statement tends to make the argument true (unless your actually converting the null to something or checking for nulls).

This is just my opinion based on observation though, not an official answer.


I would suggest that you not count on Null continuing to break the way it is now. One option would be to add a check for NULL and set it to "" before you get to the If statement, just to be sure. Another would be to do it in your SQL statement if your using a server that allows it. For SQL Server you could return IsNull(DatePaid,'') AS DatePaid instead.

-T

 
Hi Jedel
Try testing the value of MyMonth like if value <1 then as i dont think its seeing "" as null try value as i see it both codes above are wrong
God Bless
DATCAT PASTOR CRAIG CHURCHLEADERS.US
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top