Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking for a way to convert a textual date and time into a CTime.
Textual date and time could be:
Quote:
"27 December 1999"
"8:30:00"
"20:30:00"
"January 25, 1996 8:30:00"
"8:30:00 Jan. 25, 1996"
"1/25/1996 8:30:00"


What I have tried:

I wrote the following function, however ParseDateTime always fail.

CTime DateTimeString2CTime(CString DateTimeStr)
{
	COleDateTime t;
	if (t.ParseDateTime(DateTimeStr))
	{
		CTime result(t);
		return result;
	}
	return (CTime)NULL;
}
Posted
Updated 14-Jan-18 22:23pm
Comments
Richard MacCutchan 14-Jan-18 7:50am    
What is the actual string that you are passing in, and have you checked GetLastError() to see if that gives any further clues?
Richard MacCutchan 14-Jan-18 7:54am    
Also, I do not see a constructor in CTime Class | Microsoft Docs[^] that takes a COleDateTime value.

1 solution

The call of ParseDateTime should work for valid date string. A reason for problems could be that your locale settings on your computer arent fitting to that date format. Check that - maybe fix it with additional parameter to ParseDateTime.

Or is it another problem from the input parameter or the CTime conversion constructor?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900