I want to convert ColeDateTime to CTime

I am reading datetime from a database in format ColeDateTime. I want to convert it to CTimeto get the month date year and time.

CString repDt; //**this will hold the datetime which i read from Database**

COleDateTime dt; 
//**my datetime format is mm/dd/yyyy.**

dt.ParseDateTime(repDt);   **//this line of code gives exception**

CTime t(dt.GetYear(), dt.GetMonth(), dt.GetDay(), dt.GetHour(),
        dt.GetMinute(), dt.GetSecond());
m_time=t.GetTime();

Please give me some solution, how can I do this?

Thanks in advance.

+1
source share
2 answers

The constructor CTimeaccepts the structures SYSTEMTIMEand DBTIMESTAMP, therefore, both of them will work:

SYSTEMTIME st;
if (dt.GetAsSystemTime(st))
    t = CTime(st);

DBTIMESTAMP dbts;
if (dt.GetAsDBTIMESTAMP(dbts))
    t = CTime(dbts);
+4
source

Please, try

COleDateTime dt=COleDateTime(2013, 12, 12,12,12,56);
CTime ctime;
SYSTEMTIME systime;
dt.GetAsSystemTime(systime);
ctime = CTime(systime);
+1
source

Source: https://habr.com/ru/post/1758144/


All Articles