Solved

Getting right time....

Posted on 2000-04-14
7
201 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
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 100 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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