- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Converting strings to dates

Question:

I want to convert strings to dates, but StrToDate doesn't do what I want. I want to convert "December 6, 1969" to a TDateTime. What should I do?

Answer:

StrToDate only converts numbers, so if you have month names in
your string, you'll have to use VarToDateTime instead. Here are
some examples:

  var
    D1, D2, D3 : TDateTime;
  begin
    D1 := VarToDateTime('December 6, 1969');
    D2 := VarToDateTime('6-Apr-1998');
    D3 := VarToDateTime('1998-Apr-6');
    ShowMessage(DateToStr(D1)+' '+DateToStr(D2)+' '+
                DateToStr(D3));
  end;



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile