如果是自己编写的内嵌在程序中的查询条件式,我觉得把从数据字段中取出的数据转换成文本格式再进行检索,速度比较快些。
如:
(Access)
'open database
set db_in=...
'open table
set tb_in=...
do until tb_in.eof
if tb_in([日期字段的字段号])="检索条件" then
print tb_in(1)
end if
tb_in.movenext
loop
tb_in.close
db_in.close
Access中用#1999-1-2#
Sql Server中用 SELECT * FROM Northwind.dbo.Orders WHERE OrderDate < 'May 1, 1997' or ‘4/15/1998’
另:有关Sql Server的DateTime如下:
When specifying dates in comparisons or for input to INSERT or UPDATE statements, use constants that are interpreted the same for all language settings:
ADO, OLE DB, and ODBC applications should use the ODBC timestamp, date, and time escape clauses of:
{ ts 'yyyy-mm-dd hh:mm:ss[.fff] '} such as: { ts '1998-09-24 10:02:20' }
{ d 'yyyy-mm-dd'} such as: { d '1998-09-24' }
{ t 'hh:mm:ss'} such as: { t '10:02:20'}
Applications using other APIs, or Transact-SQL scripts, stored procedures, and triggers should use the unseparated numeric strings for example: yyyymmdd as 19980924.
Applications using other APIs, or Transact-SQL scripts stored procedures, and triggers can also use the CONVERT statement with an explicit style parameter for all conversions between the date and smalldate data types and character string data types. For example, this statement is interpreted the same for all language or date format connection settings:
SELECT *
FROM Northwind.dbo.Orders
WHERE OrderDate = CONVERT(DATETIME, '7/19/1996', 101)