Select Between Date Range from Access Database in ASP

The database is called 'dbDate', the table 'tblDate' and date field 'dDate'. The 'dDate' field is a DATE/TIME datatype. Our code selects all the dates between the two variables dDateFrom and dDateTo.

<%
Dim connection, recordset
Dim SQL, sConnString, dDate, dDateFrom, dDateTo

dDateFrom=#2003-12-07#
dDateTo=#2005-12-08#

SQL="SELECT dDate FROM tblDate WHERE dDate BETWEEN " & dDateFrom & " AND " & dDateTo

sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("datedb.mdb")

Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset")
connection.Open(sConnString)
recordset.Open SQL, connection
If Not recordset.Eof Then
Do While Not recordset.Eof
dDate=recordset("dDate")
Response.write dDate & "<br />"
recordset.movenext
Loop
Else
Response.write "There are no records."
End If

Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
%>

Change date format from DDMMYYYY to MMDDYYYY Format

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Free ASP Hosting