Главная страница | назад





Article #18006: Converting strings to dates

 Question and Answer Database
FAQ3006D.txt Converting strings to dates
Category :Miscellaneous
Platform :All
Product :All 32 bit
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;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99