function valid=valid_date(y,m,d)
valid = false;
if(((isscalar(y) && y>=1 && y==fix(y))&& (isscalar(m) && m>=1 && m==fix(m) && m<=12)...
&& (isscalar(d) && d>=1 && d==fix(d) && d<=31))==1)
c1= (ismember(m,[4,6,9,11]) && ismember(d,[1:30]));
c2=(ismember(m,[1,3,5,7,8,10,12]) && ismember(d,[1:31]));
if ((c1==1 || c2==1)==1)
valid = true;
else
if ((mod(y,4)==0&&mod(y,100)~=0 || mod(y,400)==0&&mod(y,100)==0)==1)
if (ismember(d,[1:29])==1)
valid = true;
end
return;
else
if (ismember(d,[1:28])==1)
valid = true;
end
return;
end
end
6 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714499
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714499
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714643
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714643
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714678
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714678
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714825
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_714825
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_1266270
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_1266270
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_1266545
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/466971-if-else-problem-for-year#comment_1266545
Sign in to comment.