Date Range Question

  • Thread starter Thread starter Aleks
  • Start date Start date
A

Aleks

Hi,

I have a query that returns date/time, I only want to display the records
which the date is same as today, regardless of the time, I tried:

Select * from table
Where LoginTime =getdate()

But I don't get the results I need.

How should the query be so that I only get the records where LoginTime
(date) is equal as the today's date ?

Aleks
 
SELECT Table.*, Table.logintime
FROM Table
WHERE (((Table.logintime)=Date()));
--


---------------------------------------------------------------------
"Are you still wasting your time with spam?...
There is a solution!"

Protected by GIANT Company's Spam Inspector
The most powerful anti-spam software available.
http://mail.spaminspector.com
 
You should keep in mind that Date() still has a time component. Although
that component is 00:00:00 (midnight), it is still there, and any
comparisons made on it must be made in consideration of that fact. The
following code will demonstrate this point.

Dim dte1 As Date
Dim dte2 As Date

dte1 = Date
dte2 = Now

If dte1 = dte2 Then
MsgBox "dte1=dte2"
Else
MsgBox "dte1<>dte2"
End If

MsgBox "dte1: " & _
Format(dte1, "dd/mm/yyyy hh:nn:ss") & _
vbCrLf & "dte2: " & _
Format(dte2, "dd/mm/yyyy hh:nn:ss")

Also some SQL comparisons using the BETWEEN operator fail to return certain
records where the date has been created with Date().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
Back
Top