![]() |
StrToDate
Hallo,
Warum funktioniert diese Zeit Umwandlung nicht? Habe ich etwas übersehen? (D6: function StrToDate(const S: string): TDateTime;)
Delphi-Quellcode:
var
DateStr :string; begin ShortMonthNames[5] := 'Mai'; DateStr := '23-Mai-2008'; DateSeparator := '-'; LongDateFormat := 'dd-mmm-yyyy'; DateTimePicker1.DateTime := StrToDate(DateStr); end; Zitat:
|
Re: StrToDate
![]() |
Re: StrToDate
Zitat:
|
Re: StrToDate
Zitat:
|
Re: StrToDate
Ich würd mal sagen, nach dem Monatsnamen darf kein Separator kommen, aber :?:
Wieso soll er englisch brauchen? |
Re: StrToDate
Zitat:
Zitat:
|
Re: StrToDate
Versuch es mal mit der überladenen Variante der Funktion
|
Re: StrToDate
Zitat:
|
Re: StrToDate
OH: "Die Reihenfolge von Tag, Monat und Jahr wird von der globalen Variable ShortDateFormat ... bestimmt"
... und nicht LongDateFormat |
Re: StrToDate
Zitat:
Delphi-Quellcode:
oder
ShortDateFormat := 'dd-mmm-yyyy';
Delphi-Quellcode:
ShortDateFormat := 'd/m/y';
|
Re: StrToDate
Zerlege den String und erzeuge daraus das Datum
|
Re: StrToDate
|
Re: StrToDate
Zitat:
|
Re: StrToDate
Hallo,
das Prinzip bleibt das gleiche:
Delphi-Quellcode:
Grüße vom marabu
function StrToDate(s: string): TDateTime;
var iMonth, nMonth: Integer; sMonth: string; begin iMonth := Pos('mmm', ShortDateFormat); if iMonth > 0 then begin sMonth := Copy(s, iMonth, 3); nMonth := Low(ShortMonthNames) + AnsiIndexText(sMonth, ShortMonthNames); Str(nMonth:2, sMonth); s := StuffString(s, iMonth, 3, sMonth); end; Result := SysUtils.StrToDate(s); end; |
Re: StrToDate
Zitat:
|
Re: StrToDate
@marabu. Danke! Das funktioniert endlich.
Verwende die Funktion nun so:
Delphi-Quellcode:
function StrToDateTime(s: string): TDateTime;
var iMonth, nMonth: Integer; sMonth: string; begin iMonth := Pos('mmm', ShortDateFormat); if iMonth > 0 then begin sMonth := Copy(s, iMonth, 3); nMonth := Low(ShortMonthNames) + StrUtils.AnsiIndexText(sMonth, ShortMonthNames); Str(nMonth:2, sMonth); s := StuffString(s, iMonth, 3, sMonth); end; Result := SysUtils.StrToDateTime(s); end; procedure TForm1.Button1Click(Sender: TObject); var DateStr: string; dtDateTime: TDateTime; Begin DateStr := '23-Mai-2008 17:01'; DateSeparator := '-'; TimeSeparator := ':'; ShortDateFormat := 'dd.mmm.yyyy'; dtDateTime := StrToDateTime(DateStr); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:20 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz