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.
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.
From here (paraphrased):
StrToDate does not use ShortDateFormat to check the actual format; it uses it only to determine the order of y,m,d and then uses DateSeparator to determine the actual date separator character.
So what you need is:
ShortDateFormat := 'd/m/y';
DateSeparator := '/';
j:=StrToDate('05/05/1999');
You may want to think about either:
ShortDateFormat
and DateSeparator
before doing this so you can restore them (they're set initially based on your locale); orInsert 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.1999
it does work.