home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
COMPDATE.CMM
< prev
next >
Wrap
Text File
|
1995-09-18
|
2KB
|
58 lines
// CompDate.cmm - Compare two dates, using exit code to indicate if
// ver.1 before date, on date, or after date.
// Exit: 0 if date1 < date2
// 1 if date1 = date2
// 2 if date1 > date2
// 3 if error on date input
//
Instructions()
{
puts(`CompDate - Compare two dates`)
puts("\a")
puts(`USAGE: CEnvi CompDate date1 [date2]`)
puts(``)
puts(`WHERE: date1 - first date in MM/DD/YY or MM/DD/YYYY format`)
puts(` date2 - second date in MM/DD/YY or MM/DD/YYYY format; optional,`)
puts(` if not supplied then used today's date`)
puts(``)
puts(`EXIT: Exit codes may be the followin`)
puts(` 0: date1 < date2`)
puts(` 1: date1 = date2`)
puts(` 2: date1 > date2`)
puts(` 3: date1 or date2 invalid`)
puts(``)
exit(3);
}
main(argc,argv)
{
if ( argc == 2 ) {
date1 = ConvertDateToYYYYMMDD(argv[1]);
// no date2 supplied, so use current time
strftime(date2,"%Y%m%d",localtime(time()));
} else if ( argc == 3 ) {
// date1 and date2 are supplied
date1 = ConvertDateToYYYYMMDD(argv[1]);
date2 = ConvertDateToYYYYMMDD(argv[2]);
} else {
// invalid input
Instructions();
}
// return comparisons of dates, return 0, 1, or 2
if ( comp = strcmp(date1,date2) )
comp = ( comp < 0 ) ? -1 : 1 ;
return comp + 1;
}
ConvertDateToYYYYMMDD(mmddyy)
{
if ( 3 != sscanf(mmddyy,"%d/%d/%d",Month,Day,Year) )
Instructions();
if ( Year < 1000 ) // always use 4-digit year
Year += ( Year < 20 ) ? 2000 : 1900 ;
sprintf(yyyymmdd,"%04d%02d%02d",Year,Month,Day);
return yyyymmdd;
}