比较日期:
unsigned long Compare_To_Date(char* datetime1,char* datetime2){
unsigned short year1;
unsigned short month1;
unsigned short day1;
unsigned short year2;
unsigned short month2;
unsigned short day2;
unsigned long bValidate;
bValidate=Validate_Date(datetime1,&year1,&month1,&day1);
if(bValidate==false){
return 3;
}
bValidate=Validate_Date(datetime2,&year2,&month2,&day2);
if(bValidate==false){
return 3;
}
if(year1<year2) return 0;
if(year1>year2) return 2;
if(month1<month2) return 0;
if(month1>month2) return 2;
if(day1<day2) return 0;
if(day1>day2) return 2;
return 1;
}
unsigned long Compare_To_Current_Date(char* datetime){
unsigned short year;
unsigned short month;
unsigned short day;
unsigned long bValidate=Validate_Date(datetime,&year,&month,&day);
if(bValidate==false){
return 3;
}
SYSTEMTIME CurTime;
GetLocalTime(&CurTime);
if(CurTime.wYear>year)
return 2;
else if(CurTime.wYear<year)
return 0;
if(CurTime.wMonth>month)
return 2;
else if(CurTime.wMonth<month)
return 0;
if(CurTime.wDay>day)
return 2;
else if(CurTime.wDay<day)
return 0;
return 1;
}
unsigned long Validate_Date(char* date,unsigned short * year,unsigned short * month,unsigned short * day){
if(strlen(date)!=10) return false;
string s(date);
if(s.substr(2,1)!="/") return false;
if(s.substr(5,1)!="/") return false;
string szyear=s.substr(6,4);//dd/mm/yyyy
string szmonth=s.substr(3,2);
string szday=s.substr(0,2);
if(IsNumber(szyear)==false) return false;
if(IsNumber(szmonth)==false) return false;
if(IsNumber(szday)==false) return false;
unsigned long bResult;
try{
*year=(unsigned short)atol(szyear.c_str());
*month=(unsigned short)atol(szmonth.c_str());
*day=(unsigned short)atol(szday.c_str());
bResult= true;
}catch(){
bResult=false;
}
return bResult;
}