Often we encounter such a problem: first, the last day of a month is 29, 30, or 31? The second is to return to the last day of a month. This problem if, inadvertently, the SQL of the date of the statement, contains the wrong date, then there will be errors, then how to solve it? Please refer to the following code.
public string Monthmaxday (long Year,long month,int Flag)
{//Get month Livestock Day
String value,svalue = "";D atetime Dt;int Day;
if (month==0)
{
month=month+1;
Year=year-1;
}
if (flag>0)
{
svalue=year.tostring ("0000") +month.tostring ("00") + "28";
for (day=29;day<=31;day++)
{
Try
{
Value= month.tostring ("") + "/" + Day + "/" +year.tostring ("0000");
Dt=convert.todatetime (Value);
value=year.tostring ("0000") +month.tostring ("a") +day;
Svalue=value;
}
catch (Exception Errdis)
{
Errdiscroption=errdis.tostring ();
Goto ERRHD;
}
}
}
Else
{
svalue=year.tostring ("0000") +month.tostring ("00") + "01";
}
ERRHD:
return svalue;
}