Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

FormatStrToDateTime

ivo jonkerivo jonker Member Posts: 13
Hello all,

Somewhat a strange subject i guess :) Anyway, here's what i'm looking for.

i'm reading some text files.. and the dates provided in those texts are always in this format: February 26, 14:38:40 ET 2007

Now i wonder, is there something such as...

Function FormatSTrToDateTime(String, Format):Tdatetime;

So i can do for example:

Mydate:=FormatStrToDateTime('February 26, 14:38:40 ET 2007','MMMM dd, hh:mm:ss "ET" YYYY');


Thanks all.

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello all,
    :
    : Somewhat a strange subject i guess :) Anyway, here's what i'm looking for.
    :
    : i'm reading some text files.. and the dates provided in those texts are always in this format: February 26, 14:38:40 ET 2007
    :
    : Now i wonder, is there something such as...
    :
    : Function FormatSTrToDateTime(String, Format):Tdatetime;
    :
    : So i can do for example:
    :
    : Mydate:=FormatStrToDateTime('February 26, 14:38:40 ET 2007','MMMM dd, hh:mm:ss "ET" YYYY');
    :
    :
    : Thanks all.
    :
    No, but you could write such a function. The easiest way is to use/write a copy or delete parser.
  • ivo jonkerivo jonker Member Posts: 13
    Yup, that was the alternative i had in mind.

    Thanks a lot, i appreciate your quick awnser. Been a while since i've written in delphi. I still like the language :)


  • zibadianzibadian Member Posts: 6,349
    : Yup, that was the alternative i had in mind.
    :
    : Thanks a lot, i appreciate your quick awnser. Been a while since i've written in delphi. I still like the language :)
    :
    :
    :
    Since you know the exact format you can start with that format instead of a generalized function. Here's part of such a function:
    [code]
    function MyStrToDate(s: string): TDateTime;
    var
    t: string;
    y, m, d: word;
    h, n, s, ms: word;
    begin
    t := Stringsplit(s, 0, ' ');
    m := FindMonth(t);
    t := Stringsplit(s, 1, ' ');
    Delete(t, Length(t), 1);
    d := StrToInt(t);
    t := Stringsplit(s, 2, ' ');
    h := StrToInt(Stringsplit(t, 0, ':'));
    n := StrToInt(Stringsplit(t, 1, ':'));
    s := StrToInt(Stringsplit(t, 2, ':'));
    t := Stringsplit(s, 4, ' ');
    y := StrToInt(t);
    end;
    [/code]
    I left the ET away, and the date still needs to be encoded from the variables. The StringSplit() function is in the CodePedia.
Sign In or Register to comment.