datepascalfreepascal

pascal string to date


Can someone tell me what's wrong with this piece of code:

ShortDateFormat := 'dd/mm/yyyy';
j:=StrToDate('05/05/1999');

I keep getting

An unhandled exception occurred at $000000000042FA33 :
EConvertError : Invalid date format

I'm using fpc.


Solution

  • Insert this in your code before the StrToDate call:

    Writeln(DateTimeToStr(Date));

    If the output does not contain / but another character, you must use this character as separator in your string.

    On my system this gives: 11.11.2009. If I then use 05.05.1999it does work.