Selecting 'old' date results in incorrect date for some months

When choosing an old date from the calendar, the date that is select is incorrect.
For example, if the current month is June and 31st of May is selected, the date is set to 1st of May. It occurs when the current month has more days than the previous month.