Click to See Complete Forum and Search --> : date datatypes and functions
This is the problem. I what to read in a start date and an end date and then be able to put all the dates between the two in an array. I think there is a class in c++ already does anyone know the header file and datatype that I need to use. Please Help
Troy T
May 3rd, 1999, 07:49 PM
What type of output are you expecting? If you just want to specify a start date/time, and an end date/time, you can use two COleDateTime objects, and then do something like this:
COleDateTime startdate;
COleDateTime enddate;
COleDateTimeSpan datespan = startdate - enddate;
Hope this helps..
- Troy
I can't use the COLe datatype I have to be able to port this to a mac. Thanks for the help thou. What I need to do is get a user inputed date into a datatype then take the end date and get all the dates between them. I was told by someone that I can use datetime but I can't find which headerfile it is in.
Louis
Troy T
May 3rd, 1999, 08:15 PM
Do you need to get the difference between the two dates, or if the start date is 4/1/1999, and the end date is 4/5/1999 do you want 3 days, or do you expect to get the following:
4/2/1999
4/3/1999
4/4/1999
?? I am trying to get a good idea of what your expected output will be, that way I can better help you..
- Troy
I need all the dates between the two. such as
input start mon 4/03/1999
input end wed 4/05/1999
output
mon 4/03/1999
tue 4/04/1999
wed 4/05/1999
the dates will prob. be wed 01/25/1999
wed 05/13/1999
and I need all the dates between them.
Thanks for your help
Troy T
May 3rd, 1999, 09:36 PM
Okay, good deal. Thanks for the explanation on the end result that you're trying to achieve. Here is an excerpt from something I wrote about a month ago to walk a date from one to another. It's somewhat custom to what I'm doing, but I'm sure you'll get the idea, and run with it.. :)
CString sDate = _T("");
int nOnDay, nYear, nMonth, nDay;
while( nOnDay <= 365 ) // Count only up to 365 (days per year)
{
if( nMonth == 1 && nDay > 31 )
{
nMonth++;
nDay = 1;
}
if( IsLeapYear(nYear) )
{
// Feb has 29 days (LEAP YEAR)
if( nMonth == 2 && nDay > 29 )
{
nMonth++;
nDay = 1;
}
}
else
{
// Feb has 28 days (NON-LEAP year)
if( nMonth == 2 && nDay > 28 )
{
nMonth++;
nDay = 1;
}
}
if( nMonth == 3 && nDay > 31 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 4 && nDay > 30 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 5 && nDay > 31 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 6 && nDay > 30 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 7 && nDay > 31 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 8 && nDay > 31 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 9 && nDay > 30 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 10 && nDay > 31 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 11 && nDay > 30 )
{
nMonth++;
nDay = 1;
}
if( nMonth == 12 && nDay > 31 )
{
nYear++;
nMonth = 1;
nDay = 1;
}
// Perform your functions here
sDate = ConvertIntToString(nMonth);
sDate += _T("/");
sDate += ConvertIntToString(nDay);
sDate += _T("/");
sDate += ConvertIntToString(nYear);
// Just for kicks, show the generated date
MessageBox( sDate );
nOnDay++;
nDay++;
}
The "BOOL IsLeapYear(int nYear)" function is shown below.
BOOL IsLeapYear(int nYear)
{
return ((nYear % 4) == 0) && ((nYear % 100) != 0) && ((nYear % 400) == 0);
}
The ConvertIntToString() function is quite trivial, but here's the code for that, too.
CString ConvertIntToString(int nConvert)
{
CString sTemp = _T("");
char cTemp[50];
_itoa( nConvert, cTemp, 10 );
sTemp = cTemp;
return sTemp;
}
Hopefully that will give you a good idea of how to make that happen. I'm not sure about how you will incorporate the day onto that date value that you're getting, but it shouldn't be too hard. Then with the above calculations, you can just build a string with nMonth/nDay/nYear added onto it. Good luck!
- Troy
Troy T
May 3rd, 1999, 09:53 PM
No problem, glad I could help. While you were reading that, I was modifying it, because I forgot a couple things. You may want to read it again, to make sure you saw the whole thing.. :)
- Troy
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.