Solved

Getting right time....

Posted on 2000-04-14
7
199 Views
Last Modified: 2010-04-02
Does anyone have som code that shows how to get todays date (just date, month and year) and store it in a variable, fra_dato. And then add 1 month to todays date and store it in another variable, til_dato??
And then compare those 2 variables.
All variables must be shown on the output. I'm having trouble getting it set up correctly.

#include <iostream.h>
#include <afx.h>

class time()
{
         ???    til_dato;
         ???    fra_dato;
public:

}

void main()
{
CTime fra_dato = CTime::GetCurrentTime();
//To make a time 1 month away:

CTime til_dato = CTime::GetCurrentTime();
int yr = til_dato.GetYear();
int mo = til_dato.GetMonth();
int da = til_dato.GetDay();
int hr = til_dato.GetHour();
int mi = til_dato.GetMinute();
int sec = til_dato.GetSecond();
if(++mo > 12){
         yr++;
}
CTime t3 = CTime(yr, mo, da, hr, mi, sec, -1);
}
0
Comment
Question by:anine
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
time_t CurTim = time(NULL);
tm CurrentTime = localtime(CurTim);
tm NextTime = CurrentTime;

++NextTime..tm_mon; // Increment month.
if (NextTime.tm_mon > 11) // If month is invalid.
{
   NextTime.tm_mon = 0; Reset to January.
   ++NextTime.tm_year; // of next year.
};


Now one problem is what do you do with days that are not valid.  Like what if today is the 31st and the next month doesn't have a 31is?  should it be the 30th of the next month?  Or the 1st of the month after that?  Or something else.
0
 

Author Comment

by:anine
Comment Utility
The answer lacks information about how you write to the screen.

0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
just cout the infrormation.

I don't know how you want it to look.  But something like

cout << CurrentTime.tm_mon << '/' <<CurrentTime.tm_mday << '/' << CurrentTime.tm_year + 1900 << endl;

It s not necesssary to reject an answer if you just want additional help or clarification.  Most problems are solved by a "dialog" between an expert and the client.  
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:anine
Comment Utility
Adjusted points from 75 to 100
0
 

Author Comment

by:anine
Comment Utility
Sorry, I'm new at this ;-)
Thank you very much!!
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
Comment Utility
Does that mean that was acceptible? Should I answer?
0
 

Author Comment

by:anine
Comment Utility
Yes, it was acceptable!
Thanx.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

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…
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 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.

763 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

6 Experts available now in Live!

Get 1:1 Help Now