|
-
Jul 6th, 2000, 09:58 AM
#1
Thread Starter
Member
I have a date/time field in my access database (ie stored like 06/07/00 12:00:00) and I wish to do an SQL to find certain dates (ie. ignoring the time part of the data) I'm doing this:
sSqlTxt="SELECT * FROM Letters WHERE DateSent = #" & Format(dtFrom.Value, "DD-MMM-YYYY") & "#"
There are many records that match this, but this sql is not picking up anything. I think is something to do with the fact that it is comparing a Date/Time with just a date.
I need the data in the database to contain the time with the date, but as far as this particular SQL goes, I just want to compare dates.
Anyone know where am I going wrong ?
Why is date handling within databases SO FIDDLY ?????
-
Jul 6th, 2000, 10:10 AM
#2
I would change the Format part to "mm/dd/yyyy" and see if you get the results you expect.
"It's cold gin time again ..."
Check out my website here.
-
Jul 6th, 2000, 10:39 AM
#3
Thread Starter
Member
No, this doesn't work. There must be a way of doing this !!
-
Jul 6th, 2000, 10:39 AM
#4
Fanatic Member
Hawker as Brucy said change the format to mm/dd/yyyy.
SQL seems to prefer it in this manner.
If you have access when you create a query with dates in them i.e. #01/02/2000#, you you can see how the SQL in SQl view changes the format to #02/01/2000#.
Gary Lowe 
VB6 (Enterprise) SP5
ADO 2.6
SQL Server 7 SP3
OK I know my spelling and grammer is crap so don't quote me on it!
To err is human to take the P! is only natural !!
Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip

-
Jul 6th, 2000, 11:10 AM
#5
Hyperactive Member
Think about your SQL statement for a minute. Is it surprising no records match midnight for the date you ask for?
Try something like this, instead:
Code:
Dim sql_str As String, dt1 As String, dt2 As String
dt1 = Format(dtFrom.Value, "#DD/MM/YYYY# ")
dt2 = Format(DateAdd(d, 1, dtFrom.Value), "#DD/MM/YYYY#")
sql_str = "SELECT * FROM Letters " & _
"WHERE DateSent > " & dt1 & _
"AND DateSent < " & dt2
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
|