[Lazarus] StrToDate and DefaultFormatSettings

Henry Vermaak henry.vermaak at gmail.com
Fri Sep 12 14:04:22 CEST 2014


On Fri, Sep 12, 2014 at 08:18:36AM -0300, "Leonardo M. Ramé" wrote:
> Hi, I need to convert strings with format "d-mmm-y" to TDateTime.
> 
> For example: '12-Sep-14'
> 
> Here's my code:
> 
> DefaultFormatSettings.DateSeparator:='-';
> DefaultFormatSettings.ShortDateFormat:='D-MMM-Y';
> DefaultFormatSettings.ShortMonthNames[1] := 'Jan';
> DefaultFormatSettings.ShortMonthNames[2] := 'Feb';
> DefaultFormatSettings.ShortMonthNames[3] := 'Mar';
> DefaultFormatSettings.ShortMonthNames[4] := 'Apr';
> DefaultFormatSettings.ShortMonthNames[5] := 'May';
> DefaultFormatSettings.ShortMonthNames[6] := 'Jun';
> DefaultFormatSettings.ShortMonthNames[7] := 'Jul';
> DefaultFormatSettings.ShortMonthNames[8] := 'Aug';
> DefaultFormatSettings.ShortMonthNames[9] := 'Sep';
> DefaultFormatSettings.ShortMonthNames[10] := 'Oct';
> DefaultFormatSettings.ShortMonthNames[11] := 'Nov';
> DefaultFormatSettings.ShortMonthNames[12] := 'Dec';
> lStr := DateToStr(now); // This works Ok.
> lDate := StrToDate(lStr); // Here I get EConvert exception.
> 
> Am I missing something?.

Have you tried ScanDateTime()?  Then you don't need to fiddle with the
format settings.

Henry




More information about the Lazarus mailing list