Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting right time....

Posted on 2000-04-14
7
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2715560
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
ID: 2716961
The answer lacks information about how you write to the screen.

0
 
LVL 22

Expert Comment

by:nietod
ID: 2717186
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:anine
ID: 2720276
Adjusted points from 75 to 100
0
 

Author Comment

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

Accepted Solution

by:
nietod earned 300 total points
ID: 2720284
Does that mean that was acceptible? Should I answer?
0
 

Author Comment

by:anine
ID: 2727667
Yes, it was acceptable!
Thanx.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

636 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