Solved

Calculating days in 360-format from SYSTEMTIME

Posted on 2006-12-01
3
563 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:WxW
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18059093
#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;
}
0
 
LVL 6

Author Comment

by:WxW
ID: 18059110
And how to convert SYSTEMTIME to a time_t ?
0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 18059139
int days360(SYSTEMTIME tm1, SYSTEMTIME tm2){
  if( tm1.wDay > 30 ){ tm1.wDay = 30; }
  if( tm2.WDay > 30 ){ tm2.wDay = 30; }
  return ((tm1.wYear-tm2.wYear)*12+tm1.wMonth-tm2.wMonth)*30+tm.wDay-tm2.wDay;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

864 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

20 Experts available now in Live!

Get 1:1 Help Now