Solved

Calculating days in 360-format from SYSTEMTIME

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 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.

707 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

17 Experts available now in Live!

Get 1:1 Help Now