CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Compare Dates within an SQL command

    I have two dtpicker controls where the user selects 2 dates: "from" and "to".
    Then I have a database where I want to select all dates between this space:
    Dates >= "from" and <= "to"
    How may I syntax the SQL command?
    Is this right?:

    dim strSQL_WHERE as string
    strSQL_WHERE = " P_FLD4 <= " & Format$(CStr(frmMain.DTPicker2.Value), "yyyy-mm-dd") & " AND P_FLD4 >= " & Format$(CStr(frmMain.DTPicker1.Value), "yyyy-mm-dd")






  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Compare Dates within an SQL command

    IMHO this depends on your backend and the settings you use for that.
    e.g in SQLServer you can use SET DATEFORMAT to define the format of your dates.

    Anyway, you need quotes around your date values as in:

    ...where date1 <= '" & format... & "' and date1 >= '" & format... & "'"





  3. #3
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Compare Dates within an SQL command

    My syntax is right. The problem is not there. The problem is how to COMPARE the dates? Is there any special way with SQL commands?
    I found for example something like this:
    {d '1999-08-24')
    But how I use it?
    I use VB6 Enterprise SP3 and the database is Paradox4 (I have created a connection with ODBC32bit DataSources -> System DSN). Nothing more...

    Michael Vlastos
    Automation Engineer
    Company Modus SA
    Development Department

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

Featured