ASP Forum
Search between two Dates
djmanvid | Posted 5:55pm 21. August 2007 Server Time |

Hello!!

I have this search but only it shows Exact dates.
I want that show dates between dates,I want Selecting records between two date range query!!!

This is my Search:
<%
Dim strURL  
Dim cnnSearch  
Dim rstSearch, rstSearch2    
Dim strDBPath  
Dim strSQL    
Dim strSearch, strSearch2  
strURL = Request.ServerVariables("URL")
strSearch = Request.QueryString("search")
strSearch2 = Request.QueryString("search2")
%>
<form action="<%= strURL %>" method="get">
  <p>
  From:
  <input name="search" value="<%= strSearch %>" />
  To:
  <input name="search2" value="<%= strSearch2 %>" />
  </p>
  <p>
    <input type="submit" />
  </p>
</form>
<p>&nbsp;</p>
<%
strDBPath = Server.MapPath("/access_db/mgdpr.mdb")
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
strSQL = "SELECT * " _
& "FROM [pagina] " _
& "WHERE Date like'%" & Replace(strSearch, "'", "''") & "%' " _
& "or Date like'%" & Replace(strSearch2, "'", "''") & "%' " _
    & "ORDER BY Date;"
Set rstSearch = cnnSearch.Execute(strSQL)
%>
<table border="1">
<tr>
<th width="128">Date</th>
<th width="118">Name</th>
</tr>
<%
Do While Not rstSearch.EOF
%>
<tr>
<td><%= rstSearch.Fields("Date").Value %></td>
<td><%= rstSearch.Fields("Name").Value %></td>
</tr>
<%
rstSearch.MoveNext
Loop
%>
</table>
<%
rstSearch.Close
Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
%>

Thanks!!!!
valkyr | Posted 2:00am 22. August 2007 Server Time |

Is Date actually stored as a datetime value or as a text value ?
Fredde | Posted 4:09am 22. August 2007 Server Time |

"SELECT field FROM table WHERE #"& date &"# BETWEEN #"& CDate(strSearch) &"# AND #"& CDate(strSearch2)&"#" might do?

djmanvid | Posted 9:15am 22. August 2007 Server Time |

Hello!!

valkyr: The Date is stored in text value.

Fredde: insert this code but it does not show any date
Fredde | Posted 9:44am 23. August 2007 Server Time |

If the date is stored as text then replace the # with '
aan43 | Posted 11:29pm 23. August 2007 Server Time |

Based on my experiences, if you need to use date in WHERE statement it should be in YYYY-MM-DD format....and CDATE wont help you... trust me :) ...

shynermark | Posted 6:49am 14. September 2007 Server Time |

How can I insert Picture into access database and rtrive it using visual basic 6.

Shyner
Tawni | Posted 9:04pm 8. November 2007 Server Time |

Date is a Reserved word no ?  

Try Change Table to something like

D_ate


Reply to Post Search between two Dates



Back to Forum Page