|
Question : Conert "text" to CTime
|
|
I have a date/time structure in a text file in the following format: "21APR001219" which represents DDMONYYHHMM Is there a single function that can convert this to a CTime class (or any date/time class or structure in VC++)? I have been able to use mid, sscanf, and CTIME construct to accomplish this task. However, I was just wondering if there is any single function or a VERY limited group of functions that could be used instead. P.S. The CTIME variable will eventually be loaded into SQL-server date/time field.(RFX)
This is some ROUGH code that I have created so far: CString str_filetime ("21APR001219"); //Just for testing CString str_fileDD(str_filetime.Mid(0,2)); //parse CString str_fileYY(str_filetime.Mid(5,2)); ... int theDD, theYY ... sscanf(str_fileDD, "%d", &theDD); //convert sscanf(str_fileYY, "%d", &theYY); ... CTime theDate((2000 + theYY), theMON, theDay, theHH, theMM, 0);//create
Thanks!
|
|
Answer : Conert "text" to CTime
|
|
I dont think there's any direct function that could get you a CTime from the format that you have given. But if you could change the STRING FORMAT of the datetime a little, then you could use the ParseDateTime function of the COleDateTime class to directly get a COleDateTime member (it is more efficient that using a CTime anyway).
ParseDateTime( LPCTSTR lpszDate);
This can take any of the following formats of string datetimes.
"25 January 1996" "8:30:00" "20:30:00" "January 25, 1996 8:30:00" "8:30:00 Jan. 25, 1996" "1/25/1996 8:30:00"
|
|
|
|