Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread How to check if a date is a valid date?
Fri, May 9 2014 1:50 PMPermanent Link

Sergei Safar

Hi,

I tried the code below but it never gets into the exception:

procedure TForm1.Edit1Exit(Sender: TObject);
var
  S : DateTime;
begin
  try        
     S := StrToDate(Edit1.Text);
     ShowMessage(DateToStr(S) + ' is a valid date');
  except
     ShowMessage('Invalid date!');
  end;
end;

Best regards,
Sergei Safar
Sat, May 10 2014 5:05 AMPermanent Link

Matthew Jones

> I tried the code below but it never gets into the exception:

1. What dates are you entering?

2. Have a look at the framework code to see what it is doing.

3. Give them a date picker - I think I saw someone post one in the
attachments topic. Wouldn't be hard to do anyway and much more reliable.

--
Matthew Jones
Sat, May 10 2014 6:31 AMPermanent Link

Uli Becker

Sergei,

> I tried the code below but it never gets into the exception:

Because there isn't any exception to raise: it's different from Delphi.
In Javascript you will get "NaN" ( = NotANumber, which is a string)
instead of an exception.

Didn't you see "NaN/NaN/NaN is a valid date" in your first ShowMessage?

Uli
Tue, May 13 2014 1:46 PMPermanent Link

Sergei Safar

Hi Matthew,

thanks for the reply.  

> 3. Give them a date picker - I think I saw someone post one in the
attachments topic. Wouldn't be hard to do anyway and much more reliable.

Datepick2 in the Elevate Web Builder Demos and Examples did the job. Thank you.

Best Regards,
Sergei Safar
Tue, May 13 2014 1:55 PMPermanent Link

Sergei Safar

Hi Uli,

> Didn't you see "NaN/NaN/NaN is a valid date" in your first ShowMessage?

Yes, that's right. The NaN's were there. I need to open my mind: Delphi <> JS

Best regards,
Sergei Safar
Image