Date searching
06-Jul-94 16:00:46
Sb: #41694-Date searching
Fm: Peter Wade 100265,2740
To: Henry Williams 73527,1446
Your first if statement will not work. The && on all tests means that the
month must be >= the 'from' month and <= the 'to' month, but if the date
range crosses a year end this may not be valid, e.g. if 'from' is
01/12/1993 and 'to' is 01/01/1994 then no month will pass this test (N.B.
I am using British dd/mm/yy format here).
The thing to remember is that if the year is greater than the 'from' year
you should not test the 'from' month, but if the years are equal you do
test the month. A similar condition applies to the day, and to the 'to'
month and day. For example :
date_ok = TRUE ;
if ( year < from.year || year > to.year )
date_ok = FALSE ;
else
{
if (( year == from.year && month < from.month ) ||
( year == to.year && month > to.month ))
{
date_ok = FALSE ;
}
else
{
if ((year == from.year && month == from.month && day < from.day)||
(year == to.year && month == to.month && day > to.day ))
{
date_ok = FALSE ;
}
}
}
P.S. I don't know about Manx, but SAS has library funtions which use long
integers that store time/date values as the number of seconds since
00:00:00 Greenwich Mean Time, January 1, 1970. If your compiler can do
this then it makes date/time comparisons a lot easier.
Peter Wade
Autopiloting from London, England