procedure TForm1.Button1Click(Sender: TObject); var strSql:string; begin query1.Close ; query1.SQL.Clear ; strSql:='select * from hdate where (hdate>='1/1/2003') and (hdate<='1/1/2004')'; query1.SQL.Add(strSql); query1.Open; end;
----------------------------------------------
-
利用参数吧: Query1.Close; Query1.SQL.Clear; Query1.SQL.Add(Select * From "lll" Where Hdate Between :Data1 and :Data2;) Query1.ParamByName('Data1').AsDateTime:=<你的第一个时间>; Query1.ParamByName('Data2').AsDateTime:=<你的第二个时间>; Query1.Prepare; Query1.Open;
----------------------------------------------
-
There are two acceptable formats for the date parts of DATE and TIMESTAMP literals in local SQL statements: the US date format and the European date format. Which one of the two you use is predicated on the Windows configuration settings for Date Separator and Short Date Style. If the Date Separator is a slash (/) and Short Date Style puts the month before the day (such as MM-dd-yy), the date must be in a US date format, MM/DD/YY or MM/DD/YYYY. If the Date Separator is a period (.) and Short Date Style puts the day before the month (such as dd.MM.yy), the date must be in a European date format, DD.MM.YY or DD.MM.YYYY. A combination of Short Date Style of month before day and a Date Separator of anything but a period is not supported in local SQL. DATE and TIMESTAMP values passed to an SQL statement via parameters and the values in columns are unaffected by these restrictions on format. Only literal values are affected.
To prevent date literals from being mistaken by the SQL parser for arithmetic calculations, enclose them in quotation marks. This keeps 1/23/1998 from being mistaken for 1 divided by 23 divided by 1998.
Example of a date literal in a US format:
SELECT *
FROM Orders
WHERE (SaleDate <= "1/23/1998")
Example of the same date literal in a European format:
SELECT *
FROM Orders
WHERE (SaleDate <= "23.1.1998")
Leading zeros for the month and day fields are optional.
If the century is not specified for the year in a date value, the BDE settings FOURDIGITYEAR and YEARBIASED control the century of the date.
----------------------------------------------
-