|
-
Dec 3rd, 2002, 08:45 AM
#1
Thread Starter
Lively Member
Database writing
Hi,
I am having problems with my vb code finding records in an access 2000 database by date.
does the date format have to be the same in the data base as the one i a using in my code ie
my sql is :-
"SELECT * From LaborDB WHERE Date = #" & strDate & "#"
the date format in strDate is 2/12/2002
in the database the date is 02/12/2002 but the above sql returns that it cannot find it.
I am using a adodb.connection
Thanks for any help
Joolz
-
Dec 3rd, 2002, 08:57 AM
#2
Addicted Member
Try changing the data type of your date variable to date... as opposed to string.
-
Dec 3rd, 2002, 09:19 AM
#3
Thread Starter
Lively Member
-
Dec 3rd, 2002, 09:24 AM
#4
Hyperactive Member
SELECT * From LaborDB WHERE Date = #" & strDate & "#"
the date format in strDate is 2/12/2002
change it to
SELECT * From LaborDB WHERE Date = "& chr(39) & strDate & Chr(39) & ";"
the date format in strDate is 2/12/2002
When pasing a SQL statement from code, I have found that using the # sign doesnt work.
Swoozie
Somedays you just should not get out of bed.
-
Dec 3rd, 2002, 11:05 AM
#5
Thread Starter
Lively Member
Dates
Hi,
I have found a daft solution, my computers date is set to
day/month/year and appears this way in access
If i search using #day/month/year# if does not find anything
but
If i search using #month/day/year# it works, i smell the americans buggering me about.
Can anyone tell me why this is, a bag of chips to the winner
Thanks
Joolz
-
Dec 3rd, 2002, 11:11 AM
#6
Frenzied Member
It's just the way Access is designed. Each database is different (to keep you on your toes!).
One way I've found to overcome the problem is to do this:
VB Code:
"SELECT * From LaborDB WHERE Date = #" & format(strDate, "dd mmm yyyy") & "#"
Not elegant, but it seems to do the trick..!
-
Dec 3rd, 2002, 11:19 AM
#7
Thread Starter
Lively Member
Dates
Thanks
Your the daddy,
Joolz
-
Dec 3rd, 2002, 07:14 PM
#8
Junior Member
another way :
"SELECT * From LaborDB WHERE Date = #" & cdate( 2/12/2002 )& "#"
johan
-
Dec 3rd, 2002, 07:35 PM
#9
Fanatic Member
format(dateVar, "dd-mmm-yyyy") is my best friend
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
|