// 读取日期 var = m_pResultSet->GetCollect(_variant_t("Birth_Time")); DATE dt = var.date; COleDateTime da = COleDateTime(dt); CString strData = da.Format(_T("%Y-%m-%d")); m_GridList.SetItemText(m_nRow, m_nColumn, strData); // 写入日期 COleDateTime oleDate = COleDateTime::GetCurrentTime(); CString strDate = oleDate.Format(_T("%Y-%m-%d %H:%M:%S")); m_pBorrowRS->Fields->GetItem(_variant_t("Borrow_Date"))->PutValue(_variant_t(strDate)); m_GridList.SetItemText(m_nRow, m_nColumn, strDate); 或: COleDateTime oleDate = COleDateTime::GetCurrentTime(); _variant_t vtDate; vtDate.vt = VT_DATE; vtDate = oleDate.Format(_T("%Y-%m-%d %H:%M:%S")); m_pBorrowRS->Fields->GetItem(_variant_t("Borrow_Date"))->PutValue(vtDate); m_GridList.SetItemText(m_nRow, 3, (LPCTSTR)_bstr_t(vtDate)); COleDateTime::GetCurrentTime() var.date \ / \ / \ / COleDateTime oleDate; / \ / \ / \ var = oleDate.Format(...) strDate = oleDate.Format(...)
也可以是用sql语句直接插入的方式:
strSql.Format(_T("update SESSIONS set BLOGGEDON = 0 ,DATE_LOGOFF = to_date('%s', 'YYYY/MM/DD HH24:MI:SS') where ID = '%s'"),
这就是直接插入时间了
ps:
检查字符串是否为空
FieldPtr filedptrTmp = m_pRecordset->Fields->GetItem((_bstr_t)(LPCTSTR)m_strDatabaseTheoryWeight);
if ((filedptrTmp->Value.vt != VT_NULL) && (filedptrTmp->Value.vt != VT_EMPTY))
FieldPtr filedptrTmp = 。。。。