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

comparing apples to oranges, need help to compare apples to apples 1

Status
Not open for further replies.

crashc123

Technical User
Oct 3, 2001
80
US
okay I want to compare today's date with a date pulled from a DB.
If today's date = to DB Date then print "today"
If not then print "later"(at this point I don't care about dates b4 today or after)
In Access DB date is set to short date mm/dd/yyyy
here's the code( all the dates print "later" even if they are the same) :

<%
Dim CONN_STRING
CONN_STRING = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\
Dim Comdate
Dim vbShortdate
vbShortDate = 2
Comdate=FormatdateTime(now(), vbShortDate)
Response.Write comdate & &quot;<BR>&quot;
Dim cnnDBEdit, rstDBEdit ' ADO objects
Dim strSQL
strSQL = &quot;SELECT * FROM Projects;&quot;

Set rstDBEdit = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rstDBEdit.Open strSQL, CONN_STRING, adOpenForwardOnly, adLockReadOnly, adCmdText

Dim x
Do While NOT rstDBEdit.EOF
x = rstDBEdit.Fields (&quot;DateDue&quot;)

If rstDBEdit.Fields(&quot;DateDue&quot;) = Comdate Then
Response.Write rstDBEdit.Fields(&quot;DateDue&quot;)%> <%Response.Write comdate%>Today<BR><%
Response.Write
Else
Response.Write rstDBEdit.Fields(&quot;DateDue&quot;)%> <%Response.Write comdate%>Later<BR><%
End If
rstDBEdit.MoveNext
Loop
%>
 
There're few ways to do this.

You either change the database date format or convert Comdate to string, by cstr() function, and modify it to the required date format.
Afterwards, you can either change the string back to date format, by cdate() function, or change the date from database to string to do the comparison.

Regards
 
Thanks again!

I had tried cstr() but got errors, but since you said it was right, I went back and checked again. Figured out that it was the empty dates that was messing it up.(Wouldn't you know it the first on in the loop had a null value.) got rid of all those and it worked now have to take care of the null value thing. Should've done that last time I had a similar problem.

Your help is much appreciated

Sonya
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top