Select Date from Access Database

If you have read our tutorial on how to insert dates into an access database then you know that the safetest way is to insert the date in the format YYYY-MM-DD. Again when working with a date in Access always use the # delimiters in your SQL statement.

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 that are the same as 2003-12-07 or come after using the greater than or equal sign.

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

SQL="SELECT dDate FROM tblDate WHERE dDate>=#2003-12-07#"

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
%>

The SQL statement will select all the dates that are the same as today's date.

<%
SQL="SELECT dDate FROM tblDate WHERE dDate=#" & Date() & "#"
%>

Select records between a date range

Get the best ASP hosting with DiscountASP.NET - great value, money back guarantee.

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

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

Global ASP.NET Hosting Leader - Click Here