I want to get the year and month from a COleDateTime object and I want it to be as fast as possible. I have 2 options;
COleDateTime my_date_time;
int year = my_date_time.GetYear();
int month = my_date_time.GetMonth();
or
COleDateTime my_date_time;
SYSTEMTIME mydt_as_systemtime;
my_date_time.GetAsSystemTime(mydt_as_systemtime);
int year = mydt_as_systemtime.wYear;
int month = mydt_as_systemtime.wMonth;
The question is, which would be faster?
COleDateTime
stores it's internal date representation as a DATE
typedef, and so when you call GetYear()
and GetMonth()
it has to calculate these each time. In the SYSTEMTIME
case, the values of wYear
and wMonth
are stored as DWORD
s so it is just a case of retrieving the values, but there is an overhead in converting a COleDateTime
to a SYSTEMTIME
.
Thanks,
Sterren