Good idea, but you should check your function failing at some invalid dates which causes array index out of bounds.
Thanks its fixed now the problem was the month was evaluated after assumption of date having invalid month value.But still yours is faster so i would prefer people to use your version.