我想在数据库的表中查询当前时间是否在表中的的开始时间和结束时间之间,不知查询语句怎么写,请指教。。。。 我想在数据库的表中查询当前时间是否在表中的的开始时间和结束时间之间,不知查询语句怎么写,请指教。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 比如表中的“开始时间”和“结束时间”字段名为:startTimeendTimeSELECT * FROM YourTable WHERE '2008.4.8 19:00:00' BETWEEN startTime AND endTime在 VC++ 中,只要生成上边的 SQL 语句即可。 SELECT * FROM YourTable WHERE getdate() BETWEEN startTime AND endTime 我的表里每条记录都有开始1楼所说的startTime和endTime,我现在是要查询当前时间在哪些记录的startTime和endTime之间,COleDateTime currentTime = COleDateTime::GetCurrentTime(); strSQL.Format(_T("select the_time from c_timer where startTime <= '%s' and endTime >= '%s' "), currentTime ); 这样写查询语句请帮看看。 上面写的有错,这样写:COleDateTime currentTime = COleDateTime::GetCurrentTime(); strSQL.Format(_T("select the_time from c_timer where startTime <= '%s' and endTime >= '%s' "), currentTime,currentTime ); strSQL.Format(_T("select the_time from c_timer where startTime <= '%s' and endTime >= '%s' "), currentTime.Format("%y-%m-%d %H:%M:%S"),currentTime.Format("%y-%m-%d %H:%M:%S")); 我试过了,照5楼这样根据字符串来查询是不准确的,只有根据datetime来查询,但不知道'%s' 用什么来表示datetime变量。 如果时间格式为年月日,则CTime cur=CTime::GetCurrent();CString strSql.Format("select * from table where startTime<='%s' and endTime>= '%s'",cur.Format("%Y-%m-%d"),cur.Format("%Y-%m-%d"))如果不是.就参照5楼的那样做.其实只是给你一个参照本.而不是一个答案.真正答案要靠自己实现的了 你用二楼的方法直接用数据库自己的getdate() 不就好了么? strtemp1=m_timefrom.Format("%Y-%m-%d"); strtemp2=m_timeto.Format("%Y-%m-%d"); sql.Format("SELECT * FROM table WHERE table.日期 BETWEEN #%s# AND #%s#",strtemp1,strtemp2);我的这样 通过了的 m_timefrom m_timeto是COleDateTime类型 文件的写入功能 MFC多文档例子中窗口下的新建窗口为什么没有响应函数也能工作? 面向连接的服务器怎么知道他要发送的数据是发送给哪个连接 如何自定一个MFC的接口类 怎样通过系统时间产生随机数?急!!!! 怎么在VC里输入特殊字符?比如一些数学公式中的希腊字母 scanf的问题!! 如何实现windows自适应伸缩菜单? 求助,有没有高手,怎么用impostor? C++ http上传文件问题 求教,在线等,谢各位高手 怎样在文本文件中保留一定字节? 最小化托盘问题
比如表中的“开始时间”和“结束时间”字段名为:startTimeendTime
SELECT * FROM YourTable WHERE '2008.4.8 19:00:00' BETWEEN startTime AND endTime
在 VC++ 中,只要生成上边的 SQL 语句即可。
strSQL.Format(_T("select the_time from c_timer where startTime <= '%s' and endTime >= '%s' "), currentTime ); 这样写查询语句请帮看看。
strSQL.Format(_T("select the_time from c_timer where startTime <= '%s' and endTime >= '%s' "), currentTime,currentTime );
CTime cur=CTime::GetCurrent();
CString strSql.Format("select * from table where startTime<='%s' and endTime>= '%s'",cur.Format("%Y-%m-%d"),cur.Format("%Y-%m-%d"))
如果不是.就参照5楼的那样做.其实只是给你一个参照本.而不是一个答案.真正答案要靠自己实现的了
strtemp2=m_timeto.Format("%Y-%m-%d");
sql.Format("SELECT * FROM table WHERE table.日期 BETWEEN #%s# AND #%s#",strtemp1,strtemp2);
我的这样 通过了的