Conversion of Microsoft DATE to int day, int month, int year?

Posted on 2008-06-24
Last Modified: 2008-06-24
Any system or free code to convert the DATE value to the integer values representing the day, month, year?

Hi experts,

I need to convert the Microsoft data type DATE (typedef double, if I am not mistaken) to the integer values. So far I have found the code by Victor Vogelpoel Is there any "more official" code by Microsoft or any other proven code?

The value was read from a MS Access database using Microsoft.Jet.OLEDB.4.0 + ADO Recordset, thus getting the VARIANT value of the VT_DATE (the _variant_t v variable inside C++ source, value).


    Excel serial date to Day, Month, Year and vise versa

    By Victor Vogelpoel


void ExcelSerialDateToDMY(DATE SerialDate, int &nDay, 

                          int &nMonth, int &nYear)


    int nSerialDate = static_cast<int>(SerialDate);

    // Excel/Lotus 123 have a bug with 29-02-1900. 1900 is not a

    // leap year, but Excel/Lotus 123 think it is...

    if (nSerialDate == 60)


        nDay    = 29;

        nMonth    = 2;

        nYear    = 1900;



    else if (nSerialDate < 60)


        // Because of the 29-02-1900 bug, any serial date 

        // under 60 is one off... Compensate.



    // Modified Julian to DMY calculation with an addition of 2415019

    int l = nSerialDate + 68569 + 2415019;

    int n = int(( 4 * l ) / 146097);

            l = l - int(( 146097 * n + 3 ) / 4);

    int i = int(( 4000 * ( l + 1 ) ) / 1461001);

        l = l - int(( 1461 * i ) / 4) + 31;

    int j = int(( 80 * l ) / 2447);

     nDay = l - int(( 2447 * j ) / 80);

        l = int(j / 11);

        nMonth = j + 2 - ( 12 * l );

    nYear = 100 * ( n - 49 ) + i + l;


Open in new window

Question by:pepr
  • 2
LVL 31

Accepted Solution

Zoppo earned 500 total points
ID: 21853532
Hi pepr,

there's a function VariantTimeToSystemTime - as arguments it has a double value represanting the DATA and a pointer to an SYSTEMTIME instance which get's filled - the SYSTEMTIME structure has members for year, month, day a.s.o.

Hope that helps,

LVL 31

Expert Comment

ID: 21853543
You could even use the COleDateTime class if you use MFC. This encapsulates calls to VariantTimeToSystemTime ...
LVL 28

Author Comment

ID: 21854128
Yes, this is what I have searched for (VariantTimeToSystemTime --



Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now