Reputation: 4789
how to convert COleDateTime to some sort of integer representation which can be easily converted back.
Upvotes: 2
Views: 2210
Reputation: 6914
I think the simplest way is through COleDateTimeSpan
as follow:
// Create an epoch
static COleDateTime epoch( 2000, 1, 1, 0, 0, 0 );
// Convert to integer
COleDateTime someTime; // initialize it from somewhere
__int64 nOleDateTimeAsInt = static_cast<__int64>( (someTime - epoch).totalSeconds() );
// Create from integer
COleDateTimeSpan span( nOleDateTimeAsInt / SecondsInDay,
(nOleDateTime % SecondsInDay) / SecondsInHour,
(nOleDateTime % SecondsInHour) / SecondsInMinute,
(nOleDateTime % SecondsInMinute) );
COleDateTime someTime( epoch + span );
Upvotes: 5