Results 1 to 6 of 6

Thread: sql problem with date

  1. #1
    cusmar
    Guest

    sql problem with date

    Hi,

    its a rookie question but my sql tag does not work
    VB Code:
    1. sqltoevoegen = "SELECT * FROM toevoegen WHERE datum BETWEEN " & Bdatum & " AND " & Edatum & " "
    2.  
    3. explaination:
    4.  
    5. toevoegen = tabel name
    6. datum = date/time field
    7. bdatum = dim bdatum as date
    8. edatum = dim edatum as date
    9.  
    10. bdatum = txtbdatum.text
    11. edatum = txtedatum.text
    my problem is that he wil not look in the field. I want that I can search between two date's

  2. #2
    Fanatic Member
    Join Date
    Apr 2002
    Posts
    638
    first of all, are you using Access or SQL Server? secondly, what error are you getting? one thing i can see is that you gotta put single quotes around the dates (that's if you're using SQL Server, use a # if it's Access):

    Code:
    "SELECT * FROM toevoegen WHERE datum BETWEEN '" & Bdatum & "' AND '" & Edatum & "'"
    otherwise, it's cos you're using SQL Server, and it doesn't like non-US dates by default, so you'd have to do this:

    Code:
    "SET DATEFORMAT DMY SELECT * FROM toevoegen WHERE datum BETWEEN '" & Bdatum & "' AND '" & Edatum & "'"
    hope that helps

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Tron :
    Sql server uses single quotes for dates ??
    What does it use from strings ?

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4
    Fanatic Member
    Join Date
    Apr 2002
    Posts
    638
    the same

  5. #5
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190
    VB Code:
    1. sqltoevoegen = "SELECT * FROM toevoegen WHERE datum BETWEEN #" & Bdatum & "# AND #" & Edatum & "# "


    my code gifs the next problems

  6. #6
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190
    sorry: i have yest press the wrong buttom

    VB Code:
    1. sqltoevoegen = "SELECT * FROM toevoegen WHERE datum BETWEEN #" & Bdatum & "# AND #" & Edatum & "# "


    my code gifs the next problems

    when i select by days smaller then 10 it fails

    a solution would by to set the date american but i havend thry this.

    when you have got the wright solution please tel me now.

    thanks.
    Heribertt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width