Click to See Complete Forum and Search --> : Compare Dates within an SQL command


Dr_Michael
August 24th, 1999, 06:12 AM
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")

Lothar Haensler
August 24th, 1999, 07:00 AM
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... & "'"

Dr_Michael
August 24th, 1999, 07:09 AM
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