ADO读写DateTime方式
// 读取日期 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(...)