Posted on 2006-03-30
Last Modified: 2010-04-01
I ahve SYSTEMTIME sysTimeA and sysTimeB

I want to know the difference in number of days.
Ex. If sysTimeA was 20 days befor sysTimeB,
then sysTimeA-sysTimeB = 20 days.

I want their difference in days. Not as: 2 week and 6 days (which I can get from SYSTEMTIME structure)
Is there any API or a way to do so?
Question by:pb_india
    LVL 20

    Expert Comment

    hi pb_india,

    hmmmm ... what about:   days_diff = weeks * 7 + days ???

    LVL 2

    Author Comment

    Nope. ABout week, that was just one example I gave. SystemTime gives in year, month, etc too. I wanted to know if there was any better API that does it already.,
    In MFC, it provides CTime(), that takes Systemtime as parameter .

    int days = CTime(sysTimeA,0)-CTime(sysTimeB,0) ;

    I am looking for something like this but without MFC
    LVL 16

    Expert Comment

    Hi pb_india,

    Use SystemTimeToFileTime to convert it.

    I quote:

    'The FILETIME structure holds an unsigned 64-bit date and time value for a file. This value represents the number of 100-nanosecond units since the beginning of January 1, 1601.'

    A little simple maths should get you what you want from there.

    LVL 2

    Author Comment

    Can you please show me the math to convert it to days?
    LVL 16

    Accepted Solution

    My documentation suggests copying the FILETIME to a ULARGE_INTEGER and then working with that.

    To get days from 100ns units (I think) you will need:

    1ns = 1/1,000,000,000seconds so 100ns = 1/10,000,000seconds
    to get minutes, divide again by 60
    to get hours, divide again by 60
    to get days divide again by 24 so

    days = <time in 100ns>/10,000,000/60/60/24 or <time in 100ns>/864,000,000,000


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    761 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

    11 Experts available now in Live!

    Get 1:1 Help Now