急,急,急。请快来帮忙(100分)

  • 主题发起人 主题发起人 Arcter
  • 开始时间 开始时间
A

Arcter

Unregistered / Unconfirmed
GUEST, unregistred user!
请问在sql查询中有一个column,字段名为END_DATE,属性是Date,在delphi程序中有一个时间变量Begin_time,如何将END_DATE字段中时间大于Begin_time的行取出。请教源程序,
 
Query1.close;
query1.sql.clear;
query1.sql.add('select * from 表名 where end_date >:pend_date);
query1.parambyname('pend_date').asdatetime:=begin_time;
query1.open;
或者
把dataset的filtered设置为true,在onfilterrecord事件中写入:accept:=dateset(table,query).fieldbyname('end_date').asdatetime >
begin_time;
 
首先要说明的是delphi中关于sql查询的日期是以”mm/dd/yy“格式,故对于Begin_time的比较要使用上面的格式。
另外,”00/4/17“指的是2000年4月17日,”99/9/9“指的是2099年9月9日!因此,要进行比较的话,就必须指定是哪一年的,如”1999/9/9“才行。

procedure ShowEnd_Data;
begin
with Query1 do
begin
close;
sql.clear;
sql.add("Select * from yourtable");
sql.add("where END_DATE>Begin_time");
open;
end;
end;

说明:
1。Begin_time的格式一定是mm/dd/yy或mm/dd/yyyy格式
2,若要在sql语句里直接比较日期,要用引号括住(单引号,paradox好象用双引号)。


 
日期格式是什么样,不是定死的,关键看您在bde中的设置。
4. Choose Date in the tree.
The settings appear on the Definition tab in the right pane.

In the following table, Parameter lists all the configurable date parameters, with their current values. When your BDE application is first installed, all values are set to their defaults.

Description briefly notes the purpose of the selected parameter.

To change a setting, highlight the desired parameter. Then replace its old value with a new value. When edits are complete, choose Object|Apply or click the Apply button to save the changes.

Parameter Description
SEPARATOR Character used to separate the month, day, and year components of a date value; such as, the "/" in "12/31/96."The default is the character normally used in the country selected in the Windows Control Panel when any BDE application is installed.
MODE Controls the order of the month, day, and year components and can be 0 (for MDY), 1 (for DMY), or 2 (YMD).The default is the order normally used in the country selected in the Windows Control Panel when any BDE application is installed.
FOURDIGITYEAR Determines how the BDE treats the century portion of a date when only the last two digits of a year are specified. If set to FALSE, the century part of the date抯 year is added automatically based on its relative position in a baseline range. If the date falls between 01/01/00 and 12/31/49, the year is considered to be in the 21st century (05/20/22 becomes 05/20/2022). If the date falls between 01/01/50 and 12/31/99, the date is considered as being in the 20th century (12/08/98 becomes 12/08/1998). A TRUE setting has no effect on dates expressed with a century (the year of a new date of 12/30/1902 remains 1902).If set to TRUE, the year for the date is assumed to be literal (no century digits automatically prefixed to the date). For example, a date expressed as 07/72/96 is considered to be the year 96 (0096).FOURDIGITYEAR has an effect in such places as date literals in SQL statements.Default value: FALSE.
YEARBIASED Tells the BDE application whether or not it should add the century to years entered as two digits. For example, if TRUE and you enter "7/21/96," the BDE application interprets your value as "7/21/1996". If set to FALSE, the date is interpreted as entered (in this case, "7/21/0096"). YEARBIASED uses the same range considerations as FOURDIGITYEAR for determining the century used.Default value: TRUE.
LEADINGZEROM Specifies whether or not single digit month values have a leading zero. For example, if you enter "1/1/80" and this is set to TRUE, the BDE application interprets the date as "01/1/80." If FALSE, the value is "1/1/80."Default value: FALSE
LEADINGZEROD Controls whether or not single digit day values have a leading zero. For example, if you enter "1/1/80" and this is set to TRUE, the BDE application interprets the value as "1/01/80." If FALSE, your date is "1/1/80."Default value: FALSE
 
Query1.close;
query1.sql.clear;
query1.sql.add('select * from table1 where end_date >:begin_date);
query1.parambyname('begin_date').asdate
:=strtodate(datetimetostr(begin_time));
query1.open;
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部