1。我建了一个acess数据库,其中有一个字段用来保存日期,我把数据类型设为“日期/时间”,可是存储的是'2002-12-12 13:34:12‘我想只存储日期2002-12-12
怎么办?
2。
在执行SQL语句
Select * from 表1 where riqi between '2002-12-12'and '2002-12-12'
怎么不行呢
我如果想查一个时间段怎么做呢?

解决方案 »

  1.   

    第一:你可以对事件格式化,留下你要的部分
    第二:时间格式不对,Access跟SQL server不一样的
      

  2.   

    _bstr_t query;
    int age;
    CString str;
    char name[12];
    strcpy(name,"02/27/1975");
    age=88; str.Format("select * from users where birthday = #%s#",name); m_list.DeleteAllItems();
    m_pRecordset->Open(_bstr_t(str),_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
    AddToList();
    m_pRecordset->Close();
    你照我这样写吧,我试过的,我能用
      

  3.   

    就是说你在程序中的时间格式化
    比如: Cstring str = COleDateTime()::GetCurrectTime().Format("%Y-%m-%d");
      

  4.   

    我想用ODBC
    不知你用的是什么
    我的字段类型是CTIME
    所以我的程序是这样写的
    CTime time;
    time=CTime::GetCurrenttime();
    m_column1=time;
    你那种方法虽然可行但好象查询的时候麻烦
    以我这样的方法存储的该怎么查询?
      

  5.   

    应该是差不多吧,下面用的是odbc,上面时adovoid CODBCSampleView::OnRecordQuery() 
    {
    // TODO: Add your command handler code here//特别的时间查询  #03/08/1975# also is ok CString birth;
    birth.Format("#1975-01-01#"); CString str;
    str.Format("select * from users where birthday=%s",birth); if(m_pSet->IsOpen())
    {
    m_pSet->Close();
    }
    m_pSet->Open(CRecordset::dynaset,str);
    UpdateData(FALSE);}
      

  6.   

    你的CTime也是应该有年月日时分秒全的巴,不可能只有年月日啊,所以要自己格式化阿
      

  7.   

    我想查一个时间段的纪录
    下面一条语句什么地方错了?
    strsql.Format("Select * from 表1 where riqo between #2002-12-24 14:35:45# and #2002-12-25 14:37:01# and number='LWJA9'");
    #什么作用〉?