Getting right time....

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;


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){
CTime t3 = CTime(yr, mo, da, hr, mi, sec, -1);
Who is Participating?
nietodConnect With a Mentor Commented:
Does that mean that was acceptible? Should I answer?
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.
anineAuthor Commented:
The answer lacks information about how you write to the screen.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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.  
anineAuthor Commented:
Adjusted points from 75 to 100
anineAuthor Commented:
Sorry, I'm new at this ;-)
Thank you very much!!
anineAuthor Commented:
Yes, it was acceptable!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.