COleDateTime and CDaoRecordsets
Jim Leavitt -- jimll@halcyon.com Saturday, February 17, 1996 Hi, Ok, I'm confused (not unusual).=20 PROBLEM: I have a CDaoRecordset using the DFX routines, class wizard made it for = me. I want to update that recordset from an ascii disk file. I read the file and update the field values. Everything works but the = COleDateTime members. Stepping through the debugger, I can see that they are set to valid and = correct dates, yet when the record is saved, they save as 12/31/1899 - essentially a = COleDateTime of 0,0,0,0,0,0. Here's what I'm doing... STUFF.... m_pHeadSet->Edit(); COleDateTime oledOrderDate(0,0,0,0,0,0); CString sOrderDate =3D sBuffer.Mid(7,8); ConvertStringToDate(sOrderDate, oledOrderDate); m_pHeadSet->m_Order_Date =3D oledOrderDate; STUFF m_pHeadSet->Update(); rest of program... where ConvertStringToDate is... BOOL CInspectorDoc::ConvertStringToDate(CString sDate, COleDateTime& = oleDate) { CString sMonth =3D sDate.Mid(0,2); CString sDay =3D sDate.Mid(3,2); CString sYear =3D sDate.Mid(6); sYear.TrimRight(); int nMonth =3D atoi(sMonth); int nDay =3D atoi(sDay); int nYear =3D atoi(sYear); oleDate.SetDate(nYear,nMonth,nDay); if (oleDate.GetStatus() =3D=3D 0) // ZERO means a valid date return TRUE; else { oleDate.SetDate(0,0,0); return FALSE; } } (Yeah I know I set the date to 0,0,0 if its invalid, but I'm not going = there, the date status shows valid.) I did find this in the docs but it doesn't seem to apply to my problem, = my "=3D" operator has a COleDateTime at each end. --------- Quoted from documentation ---------- =B7 operator =3D( varSrc ) If the conversion of the VARIANT value (or = COleVariant object) to a date/time (VT_DATE) is successful, the = converted value is copied into this COleDateTime object and its status = is set to valid. If the conversion is not successful, the value of this = object is set to zero (30 December 1899, midnight) and its status to = invalid. Any help would be very much appreciated. Jim Leavitt
Martin Wawrusch -- wawrusch@accs.co.at Monday, February 19, 1996 [Mini-digest: 2 responses] On Feb 17, 10:07pm, Jim Leavitt wrote: > Subject: COleDateTime and CDaoRecordsets > CString sMonth = sDate.Mid(0,2); > int nMonth = atoi(sMonth); > int nDay = atoi(sDay); > int nYear = atoi(sYear); Just a guess: int nYear = atoi(sYear) + 1900; -- Martin Wawrusch | ESBMASAP, BNS A. Einstein ACCS Software | Tel. : +43 1 983 46 91 Huetteldorferstr. 163/23 | Fax. : +43 1 983 01 00 A-1140 Vienna, Austria | EMail: wawrusch@accs.co.at -----From: Rohit NamjoshiJim, Use COleDateTime::ParseDateTime, much easier and worked fine for me. Cheers... Rohit -- Rohit Namjoshi namjoshi@austin.asc.slb.com Schlumberger Austin Systems Center Vox: +1 512 331 3353 Austin, TX 78726, USA Fax: +1 512 331 3320
| Вернуться в корень Архива |