views:

53

answers:

1

I'm new to ASP (new job uses a windows server and I've only used Linux before) and I'm building a 'log' that stores it's data into XML files. I've got it reading the XML out perfectly but now I'm trying to get it to print out data from a specific range of dates.

The way I'm doing this is by using the DateDiff function to compare the date in the XML entry to the date the user defines, this will then output a number. If this number is greater than 1 for the start date and less than one for the end date then it will be displayed. The startdate part works but no matter what date I put in the end date it will just print everything from the startdate upwards.

Here's my code

<%
Response.Buffer = True
session.lcid=2057
Set entries = Server.CreateObject("Microsoft.XMLDOM")
Set entry = Server.CreateObject("Microsoft.XMLDOM")
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load (Server.MapPath("log.xml"))

set entries = xml.getElementsbyTagName("entry")

noOfEntries = entries.length
If Request.Form("findLog") = "true" Then
    CheckLog
End If
%>
<html>
<head>
<title>GM Log</title>
</head>
<body>
<p>Please enter the dates that you want to view the log from</p>
<form name=form1 action=readlog.asp method=post>
<p>Start date: <input type=text name=startdate>End date: <input type=text name=enddate>
<input type=hidden name=findLog value=true>  <input type=submit value="Search"></p>

</form>

<%
Sub CheckLog 
     startDate = Request.Form("startdate")
     LastDate = Request.Form("enddate")
     Response.Write("<table border=5>")
     For i = 0 To (noOfEntries - 1)
         Set entry = entries.item(i)
         If isDate(entry.childNodes(0).text) Then
             meh = CDate(entry.childNodes(0).text)
             beginning = DateDiff("d", startDate, meh)
             Response.Write ("<p style=""color: red"">days from startdate: " & beginning & "</p>")
             ended = DateDiff("d", LastDate, meh)
             Response.Write ("<p>days from today: " & ended & "</p>")
             If beginning + 1 > 0 or beginning + 1 = 0 & ended < 0 or ended = 0 Then
          Response.Write("<tr>"&_
 "<td>" & entry.childNodes(0).text & "</td>"&_
 "<td>" & entry.childNodes(1).text & "</td>"&_
 "<td>" & entry.childNodes(2).text & "</td>"&_
 "<td>" & entry.childNodes(3).text & "</td>"&_
 "<td>" & entry.childNodes(4).text & "</td>"&_
 "</tr>")
             End If
       End If  

    Next
    Response.Write("<table>")
End Sub
%>

</body>
</html>

Here's my XML file layout.

<?xml version="1.0"?>
<GM>
    <entry>
         <date>15/07/2010</date>
         <time>1515</time>
          <conversation>Dave down the Pub</conversation>
          <information>This is another test.</information>
          <action>Colin Wren</action>
     </entry>
     <entry>
          <date>20/07/2010</date>
          <time>1700</time>
          <conversation>Sam</conversation>
          <information>this is a test</information>
          <action>Colin</action>
    </entry>
</GM>

I'm sure it's just me being stupid and frying my brain looking at it too long but any help would be really appreciated.

A: 

Maybe you want the following?

If beginning + 1 >= 0 And ended <= 0 Then

Note that for a logical AND operation in VB you will have to use the And operator.

0xA3
I did that originally but then I kept getting syntax errors :SEdit // I just tried this and it now prints out everything no matter what dates are entered.
Colin Wren
You might want to calculate that difference then: `ended = DateDiff("d", meh, LastDate)`?
0xA3
I can't replicate it but I tried your solution, it doesn't bring up an error but it just prints everything out. I can't see anything wrong with why that statement wouldn't work but it doesn't. It's baffling.
Colin Wren
I combined your answers and I've got the end date working, but now the start date isn't working, I think it's the other DateDiff.
Colin Wren
Yep it was the DateDiffs. Thanks so much for helping me out with this.
Colin Wren