|
If you are using MFC, see the COleDateTime class.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: If you are using MFC, see the COleDateTime class.
Nope, pure Win32
|
|
|
|
|
Ok. How are you obtaining the date value you want to manipulate?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
GetSystemTime() (then converting it to local time).
|
|
|
|
|
So do you have a SYSTEMTIME or a FILETIME object at this point?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
SYSTEMTIME.
SYSTEMTIME stDateIWantToAddDaysOrMonthsTo;
FILETIME ft, ftLocal;
GetSystemTimeAsFileTime(&ft);
FileTimeToLocalFileTime(&ft, &ftLocal);
FileTimeToSystemTime(&ftLocal, &stDateIWantToAddDaysOrMonthsTo);
|
|
|
|
|
Ok, so what problem(s) are you having with "add or subtract any amount of hours, days, months etc. to a date?"
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't know of any function that does this. I was looking for something like VBScript's DateAdd where I could do something like DateAdd(Month, 24, &stMyDate) and it would add 24 months to the date (2 years), taking into account leap years etc..
|
|
|
|
|
nm_114 wrote: I don't know of any function that does this.
Why would you need a function, when one statement will work:
stDateIWantToAddDaysOrMonthsTo.wYear += 2; You could roll your own function to this I suppose. Take a stroll through the other date/time functions to see what is available to you.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Why would you need a function, when one statement will work:
It was a bad example I guess. It needs to be arbitrary. Like DateAdd(Month, 309, mydate) , DateAdd(Day, -909, mydate) etc. I'm not sure if I'm explaining it right.
DavidCrow wrote: Take a stroll through the other date/time functions to see what is available to you.
I did. I didn't see anything like DateAdd.
|
|
|
|
|
If you convert the SYSTEMTIME structure to a FILETIME structure, you can add/subtract such values.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
nm_114 wrote: How?
By using SystemTimeToFileTime() .
nm_114 wrote: I found an article at
http://www.codeproject.com/datetime/winapi_datetime_ops.asp[^]
That article is exactly what you need.
nm_114 wrote:
but it doesn't work with months/years
That's because a month does not have a constant value (i.e., 28, 29, 30, or 31 days) like the other items do.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: nm_114 wrote:
How?
By using SystemTimeToFileTime().
Well I knew that much! I was asking how you do the adding/subtracting...
DavidCrow wrote: That article is exactly what you need.
Well not really, as it doesn't handle months/years.
DavidCrow wrote: That's because a month does not have a constant value (i.e., 28, 29, 30, or 31 days) like the other items do.
I knew that too! But it's ok, I guess what I was looking for doesn't exist (a tested/bug-free exact replica of DateAdd() in C++). Oh well .
Thanks anyway.
|
|
|
|
|
nm_114 wrote: Well not really, as it doesn't handle months/years.
I already showed you how to add months to the SYSTEMTIME object. You would add years in the same fashion. What you have to account for when adding months is to make sure to increment years accordingly. For example, if it's September and you want to add four months, you would use:
wMonth = (wMonth + 4) % 12; But you would then have to add one to the year.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yep. I guess I was hesitant to write my own because I don't know how to account for leap years, but I guess it's not critical. I'll probably use that other article and write something similar to your example for months/years.
Thanks.
|
|
|
|
|
nm_114 wrote: ...I don't know how to account for leap years...
Are you kidding? Leap year algorithms/functions are plentiful here at CP, or even Googling for them.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
See if it helps you ...
int nDay;
int nMonth;
int nYear;
struct tm *when;
time_t now, result;
time( &now );
when = localtime( &now );//conversion from UTC to system time
if(when == NULL)//Error in the calculation of time
return -1;
when->tm_mday = when->tm_mday + nDays;
result = mktime( when );
if(result == (time_t)-1)//size of time_t = 0;result=-1--->error in calculation of result
{
return -1;
}
else
{
nDay = when->tm_mday;
nMonth = when->tm_mon+1;
nYear = when->tm_year+1900;
}
impossible to understand
|
|
|
|
|
Hi All,
I'm prototyping code, and can't seem to persist a hexadecimal base. The following does not perform as expected (it still outputs base 10):
std::cout.unsetf ( std::ios_base::dec );<br />
std::cout.setf ( std::ios_base::hex );<br />
std::cout.setf ( std::ios_base::uppercase );
The alternative (which I am now trying to avoid) is:
std::cout << std::hex << 0x1000 << std::endl;
Any ideas? I'm not sure if I am not using the stream correctly, missing a Microsoft feature, or making an incorrect assumption for flag manipulation.
Thanks,
Jeff
|
|
|
|
|
So out of morbid curiosity I thought I'd like to see this in action.
Borrowing from example code:
using namespace std;
int i = 10;
cout << i << endl;
cout.unsetf( ios_base::dec );
cout.setf( ios_base::hex | ios_base::uppercase );
cout << i << endl;
cout.setf( ios_base::dec );
cout << i << endl;
cout.setf( ios_base::hex, ios_base::dec | ios_base::uppercase );
cout << i << endl;
Output:
10
A
10
a
using namespace std;
int i = 10;
cout << i << endl;
cout.setf( ios_base::hex | ios_base::uppercase, ios_base::dec );
cout << i << endl;
cout.setf( ios_base::dec );
cout << i << endl;
cout.setf( ios_base::hex, ios_base::dec | ios_base::uppercase );
cout << i << endl;
Output:
10
10
10
10
*EDIT* And, in the "working" example, why on the 3rd cout does the hex flag not nead to be unset.<br />
In fact doing so causes it to fail
-- modified at 19:03 Sunday 4th February, 2007
|
|
|
|
|
Hi Mark,
Thanks. It appears it should fall into the 'Microsoft Features' category... I still like to presume it is me (in the past, it usually is me).
Jeff
|
|
|
|
|
Hi
I made an MDI application, created a dialog, that dialog has several controls on it;when I call DoModal,all controls on it appear fine, but when I minimize the dialog, then restore it, all controls disappears, what am I doing wrong?
|
|
|
|
|
Do you have any paint on your code?
|
|
|
|
|
LLewisLiu wrote: made an MDI application, created a dialog, that dialog has several controls on it;when I call DoModal,all controls on it appear fine, but when I minimize the dialog, then restore it, all controls disappears, what am I doing wrong?
are you creating control dynamically???
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
I've attached to another window's input by calling AttachThreadInput(). I'm now trying to send text, as follows:
int size = strlen(text);
for(int i=0; i
|
|
|
|