Optimize the code by not using getDate(c) multiple times.