Solved

Calculating days in 360-format from SYSTEMTIME

Posted on 2006-12-01
3
571 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

832 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