Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I spend whole night to find out single example to convert DATE datatype of c++ to string in COMM. My interface function returns following values and i want show that values in human redable format. Like,
C++
DATE JobStartTime;
CurrentJob->get_StartTime(&JobStartTime);

And it return valules like, 16324.5455 etc.

When i go to defination of DATE it show me something like,
C++
typedef double DATE;

Which is again confuse me.As a DATE it is again double,so how would i convert it into something like,

02/05/2013 11.41.25

etc. Please help me i am very new in comm.
Posted
Updated 1-May-13 21:22pm
v4

1 solution

You tagged MFC. So you can use the COleDateTime class which uses DATE internally and provides the Format()[^] function to convert it to a string:
C++
COleDateTime dt(JobStartTime);
CString strJobStartTime = dt.Format(_T("%d/%m/%Y %H.%M.%S"));

The above formats the string like the example from your question.

[UPDATE]
When not using MFC, you can use the function that is used by COleDateTime internally: VarBstrFromDate[^].
 
Share this answer
 
v2
Comments
Coder Block 2-May-13 2:44am    
It mfc approch.I am using pure c++.So dont have CString COleDateTime.
Jochen Arndt 2-May-13 2:47am    
Then you should not tag your question with MFC.
However, I will update my answer to give you a solution without using MFC.
Coder Block 2-May-13 2:52am    
Sorry actual i just want keep studio in mind.

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