Changed Code for looping of date array