Avatar billede guzzie Nybegynder
19. september 2001 - 16:18 Der er 10 kommentarer og
2 løsninger

search for date and show results

Hi There
Im working on a script that does a search of people in my SQL database, the basic search is done but I am having craps loads of problems trying to do a search of the dates in the database

has anybody had any experience with this ?
the date comes from an input area and is in the following format

18-08-2001

when it get passed to my search script
I request it then run it thru this
Function GetMyDate2
    GetMyDate2 = FormatDateTime(Keyworda, 1)
End Function

the value that then gets inserted into my search script looks like this
20. august 2001

My problem is this
If fx I insert this date 20-08-2001
then I get the correct results back

However if i insert this date 20-03-2001
then i get the following error
\"Syntax error converting datetime from character string.\"

It only happens when I edit the month ??
Please if anybody has a good idea or has had the same problem and help would be great
Thanks
Guzzie
Avatar billede dfens Nybegynder
19. september 2001 - 16:24 #1
Have you tried using the format 2001-08-20 (yyyy-mm-dd) ?

Avatar billede guzzie Nybegynder
19. september 2001 - 16:35 #2
hi there dfens
Hmm no I...
where do I convert it ?
Or musnt I use the FormatDateTime ?
Guzzie
Avatar billede dfens Nybegynder
19. september 2001 - 16:53 #3
If your input is 18-08-2001 you can use the split function on \'-\' and then rearrange it as you wish
Avatar billede guzzie Nybegynder
19. september 2001 - 19:04 #4
Hu there dfens
I have tried that already :(
It produces the same result.
The db is set up as short date dd-mm-yyyy
I can allways throw up some source code if it would help my explanation ?
Guzzie
Avatar billede terry Ekspert
19. september 2001 - 19:23 #5
guzzie> This question has been brought up a number of times. The correct way to SELECT a date from a SQL database is to you the U.S date format which is MM-DD-YYYY.

For example; SELECT Mydate from myTable where MyDate = #12-31-2001#






Avatar billede guzzie Nybegynder
20. september 2001 - 09:33 #6
Hi There Guys

//terry # <- cant be used with your ms SQL
if it was just access then it would be no problem
butit does not get recognized :(

//dfens
How would I do a spilt function ? Do you have an example ?

Guzzie
Avatar billede terry Ekspert
20. september 2001 - 09:47 #7
So change it to MyDate = \'12-31-2001\'
Avatar billede terry Ekspert
20. september 2001 - 09:48 #8
But it still has to be in MM-DD-YYYY format!
Avatar billede dfens Nybegynder
20. september 2001 - 15:35 #9
Used in ASP:

Function ConvertDate(MyDate)
    Dim MyDateArray
    MyDateArray    = Split(MyDate,\".\")
    ConvertDate    = MyDateArray(2) & \"-\" & MyDateArray(1) & \"-\" & MyDateArray(0)
End Function
Avatar billede guzzie Nybegynder
21. september 2001 - 08:36 #10
ok thanks guys I will split the points between you 2,
terry> thanks for the info about SQL and US date format
dfens> thanks for the split function it works just fine
PS. dfens you have only \"Kommentar\" on my question and not a \"Svar\" so I cant split the points ?
Guzzie
Avatar billede dfens Nybegynder
21. september 2001 - 10:35 #11
done
Avatar billede guzzie Nybegynder
21. september 2001 - 18:40 #12
thanks again :)
have a good weekend
Guzzie
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester