1.SQL Server 2000时间需要用单引号' '括起来
strsql.Format(_T("select * from INFO where 入库时间 between "));
strsql+=BeginDate.Format( _T("'%Y-%m-%d " ));//sql server中時間需要用單引號''括起來,而access需要##括起來
strsql+=BeginTime.Format( _T("%H:%M:%S '" ));
strsql+=_T(" and ");
strsql+=EndDate.Format( _T("'%Y-%m-%d " ));
strsql+=EndTime.Format( _T("%H:%M:%S '" ));
strsql+=_T(" order by 入库时间 asc ");
2.Access中时间需用双井号# #括起来
str.Format(_T("select * from 节点信息 where 时间 between "));
str+=begindate.Format( _T("#%Y-%m-%d " ));
str+=begintime.Format( _T("%H:%M:%S# " ));
str+=_T(" and ");
str+=enddate.Format( _T("#%Y-%m-%d " ));
str+=endtime.Format( _T("%H:%M:%S# " ));
str+=_T(" order by 时间 asc ");
本文介绍了在SQLServer2000与Access数据库中正确处理时间格式的方法。针对两种不同的数据库,文章详细解释了如何使用单引号和双井号来格式化日期与时间,确保查询能够准确执行。
1111

被折叠的 条评论
为什么被折叠?



