TrustyCoder
TrustyCoder

Reputation: 4789

convert COleDateTime to ticks or integer representation

how to convert COleDateTime to some sort of integer representation which can be easily converted back.

Upvotes: 2

Views: 2210

Answers (1)

BigBoss
BigBoss

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

Related Questions