It is highly possible that you are having issues because you are not creating the Date object correctly,
Would you share your form, or part of the form so I can have a look at it?
Because the following line :
is really picky on the parametes, so if any of the substrings function doesn't return the right value, it will not create the date object and cause errors...
If you want to fix it yourself, make sure that the substrings values are correct and if they are correct, I don't know what to tell you, so maybe I should take a look at it if you cannot fix it starting from there
Hope this help!