Date Validity Check

This logic can be used to check validty of date in date month year format :

boolean checkDate(int mm, int dd, int yy){
boolean validDate = false;
if((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && yy > 2000 ){ //this means the month has 31 days fro sure
if(dd>0 && dd 0 && dd 2000)){
validDate = true;
}else if(mm == 2)
validDate = ((yy%4 ==0)&& (dd>0 && dd0 && dd<29))? true: false; //figuring out leap year
else
validDate = false;

return validDate;
}

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: