• Status: Solved
• Priority: Medium
• Security: Public
• Views: 534

# SystemTime

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?
0
pb_india
• 2
• 2
1 Solution

Commented:
hi pb_india,

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

ike
0

Author Commented:
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
0

Commented:
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.

Paul
0

Author Commented:
Can you please show me the math to convert it to days?
0

Commented:
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

Paul
0

## Featured Post

• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.