比较日期:
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
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;
![](/Images/OutliningIndicators/InBlock.gif)
unsigned long bValidate;
![](/Images/OutliningIndicators/InBlock.gif)
bValidate=Validate_Date(datetime1,&year1,&month1,&day1);
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(bValidate==false)
{
return 3;
}
![](/Images/OutliningIndicators/InBlock.gif)
bValidate=Validate_Date(datetime2,&year2,&month2,&day2);
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(bValidate==false)
{
return 3;
}
![](/Images/OutliningIndicators/InBlock.gif)
if(year1<year2) return 0;
if(year1>year2) return 2;
![](/Images/OutliningIndicators/InBlock.gif)
if(month1<month2) return 0;
if(month1>month2) return 2;
![](/Images/OutliningIndicators/InBlock.gif)
if(day1<day2) return 0;
if(day1>day2) return 2;
![](/Images/OutliningIndicators/InBlock.gif)
return 1;
![](/Images/OutliningIndicators/InBlock.gif)
}
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;
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
unsigned long Validate_Date(char* date,unsigned short * year,unsigned short * month,unsigned short * day)
{
![](/Images/OutliningIndicators/InBlock.gif)
if(strlen(date)!=10) return false;
string s(date);
if(s.substr(2,1)!="/") return false;
if(s.substr(5,1)!="/") return false;
![](/Images/OutliningIndicators/InBlock.gif)
string szyear=s.substr(6,4);//dd/mm/yyyy
string szmonth=s.substr(3,2);
string szday=s.substr(0,2);
![](/Images/OutliningIndicators/InBlock.gif)
if(IsNumber(szyear)==false) return false;
if(IsNumber(szmonth)==false) return false;
if(IsNumber(szday)==false) return false;
![](/Images/OutliningIndicators/InBlock.gif)
unsigned long bResult;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
try
{
*year=(unsigned short)atol(szyear.c_str());
*month=(unsigned short)atol(szmonth.c_str());
*day=(unsigned short)atol(szday.c_str());
bResult= true;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}catch(
)
{
bResult=false;
}
return bResult;
}