读书人

日期的比较,该如何解决

发布时间: 2012-12-17 09:31:40 作者: rapoo

日期的比较
DataModule35->qry1->SQL->Add("Select * from Card where CompareDateTime(StrToDateTime(EndTime),FormatDateTime("yyyy-mm-dd",Now())) <= 0");


我用数据库里面记录的日期与当前的日期比较,为什么这样不行,会出现错误?
[最优解释]
sql语句和c++要分开的
[其他解释]
sql中可以直接使用符合日期格式的字符串与日期类型比较
比如:
select *from table where startime>'2011-3-1'

[其他解释]
直接在SQL里判断
sql = " Select * from Card where EndTime <= GetDate()"
qry1->SQL->Add(sql)
[其他解释]

引用:
sql语句和c++要分开的

那应该如何连接呢?
[其他解释]

DataModule35->qry1->SQL->Add("Select * from Card where EndTime<:dt");
DataModule35->qry1->Paramters->ParamsByName("dt")->Value := Date();
DataModule35->qry1->Open();


[其他解释]
大概是这个思路,代码你写

读书人网 >C++ Builder

热点推荐