|
-
Aug 7th, 2000, 12:05 PM
#1
I have a database with the date field in it and I was wondering how i could use the select statement to get dates from a certain range(to be simply from one month). I tried using SELECT...WHERE thedates >= 1-1-1980 and thedates < 2-1-1980
but it didnt seem to work. Any suggestions?
thanks
-
Aug 7th, 2000, 12:12 PM
#2
Lively Member
You have to put the dates between # signs in your SQL statement.
Or you could always use a parameterized query in access. Here is an example that I have in an app I developed:
SQL Query:
Code:
PARAMETERS [Beginning date] DateTime, [Ending date] DateTime;
SELECT Status, Ticket_Number
FROM Ticket_Record
WHERE Ticket_Record.Date >= [Beginning date]
AND Ticket_Record.Date <= [Ending date] AND Ticket_Record.Status = "Referred";
VB code to pass in the parameters and run the query (I was using DAO in the example):
Code:
Function GetWeekly(sQueryName As String, sDateBegin As String, sDateEnd As String) As Integer
Dim qdf As QueryDef
Set qdf = db.QueryDefs(sQueryName)
qdf("Beginning date") = sDateBegin
qdf("Ending date") = sDateEnd
Set rs = qdf.OpenRecordset(dbOpenSnapshot)
If rs.RecordCount = 0 Then
GetWeekly = 0
Else
rs.MoveLast
GetWeekly = CInt(rs.RecordCount)
End If
rs.Close
Set rs = Nothing
Set qdf = Nothing
End Function
Hope this helps.
-
Aug 7th, 2000, 12:13 PM
#3
Lively Member
Make sure you're using the correct date format, probably like 1/1/1980 and 2/1/1980 (slash instead of hyphen). And I think dates are enclosed in #'s, like this:
SELECT...WHERE thedates >= #1/1/1980# and thedates < #2/1/1980#
-
Aug 7th, 2000, 01:37 PM
#4
You could also use "convert" to make sure the correct format is used.
The "between" operator is another option instead of using the >= and <= operators.
-
Aug 7th, 2000, 02:55 PM
#5
Frenzied Member
You haven't indicated which DBMS your database is using, the suggestions by the other posters work for Access but won't for SQL Server (it wants your dates wrapped in quotes).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|