Solved

Calculating days in 360-format from SYSTEMTIME

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

809 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