0

I am getting:

System.TypeException: Invalid date: 30/06/2016

exception as I try to enter future dates in my date of birth inputtext. To validate this I have put below code:

Date dt=Date.parse(this.bufferdate);        
if (dt > Date.Today()) {
    system.debug('today date'+Date.Today());
    isValid = false;
    isFutureBirthDateError=true;
}

Here bufferdate is string and value of DateOfBirth. Please help me with fix. thanks in advance

  • 2
    date.parse works together with user locale. Probably, you have set locale where separators or orders of numbers are different – kurunve Jun 6 '16 at 8:26
  • how bufferdate value assigned ? – Ratan Paul Jun 6 '16 at 8:51
  • @Ratan by calendar selection but user has option of editing also as it is inputtext so i am applying validation on that for not entering Future dates – Keerthan Shetty Jun 6 '16 at 9:59
  • @kurunve are you talking about the initialization what i have done for the variable in constructor – Keerthan Shetty Jun 6 '16 at 10:01
2

parse() returns the formatted string depends on the user locale. Check your locale in user record and its date format here Supported locales

From your message noticed its not accepting format(dd/mm/yyyy) 30/06/2016, so you may need to change the format of bufferdate string as per your locale like (mm/dd/yyyy or dd-mm-yyyy..) or need to change the locale in user record.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.