Link to home
Start Free TrialLog in
Avatar of WxW
WxW

asked on

Calculating days in 360-format from SYSTEMTIME

Hi, I have 2 SYSTEMTIME structures and I know how to calculate the 365-day difference between them. (FILETIME int64 etc)

My problem is to calculate the total days in a 360-day format. Excel has a function Days360 which does that, but I couldn't find something in C++.

How to do it?

Regards
Avatar of ozo
ozo
Flag of United States of America image

#include <time.h>

int days360(time_t t1, time_t t2){
  struct tm tm1,tm2,*tm;
  tm1 = *localtime(&t1);
  tm2 = *localtime(&t2);
  if( tm1.tm_mday > 30 ){ tm1.tm_mday = 30; }
  if( tm2.tm_mday > 30 ){ tm2.tm_mday = 30; }
  return ((tm1.tm_year-tm2.tm_year)*12+tm1.tm_mon-tm2.tm_mon)*30+tm1.tm_mday-tm2.tm_mday;
}
Avatar of WxW
WxW

ASKER

And how to convert SYSTEMTIME to a time_t ?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial