Q&A

  • DateField 데이터를 EditBox에 넣으면 이상한 값이 나타납니다.
아래처럼 데이터를 Integer의 데이터를 날짜 형식으로 바꿔서 EditBox에 넣을려고 하는데.. 잘 안됩니다.

다른 방법은 없나요.. 아래 데이터는 dbgrid1.Fiedls[13].AsInteger => 20011017 이런식으로 들어 가 있습니다. 그 데이터를 edit13.text에 넣으면 이상한 데이터 값이 들어가 있습니다.

고수님들 부디 도와주세요...



edit13.Text := FormatDateTime('yyyy-mm-dd', dbgrid1.Fields[13].Asinteger);

edit14.Text := FormatDateTime('hh:mm:ss', dbgrid1.Fields[14].AsInteger);

1  COMMENTS
  • Profile
    홍성락 2001.10.18 04:58
    정규성 wrote:

    > 아래처럼 데이터를 Integer의 데이터를 날짜 형식으로 바꿔서 EditBox에 넣을려고 하는데.. 잘 안됩니다.

    > 다른 방법은 없나요.. 아래 데이터는 dbgrid1.Fiedls[13].AsInteger => 20011017 이런식으로 들어 가 있습니다. 그 데이터를 edit13.text에 넣으면 이상한 데이터 값이 들어가 있습니다.

    > 고수님들 부디 도와주세요...

    >

    > edit13.Text := FormatDateTime('yyyy-mm-dd', dbgrid1.Fields[13].Asinteger);

    > edit14.Text := FormatDateTime('hh:mm:ss', dbgrid1.Fields[14].AsInteger);

    ///////////////////////////////////////////////////////////////////////////////

    FormatDateTime의 인자중 2번째는 TDateTime형입니다.

    따라서 결과는 다르게나옵니다. 그값을 EncodeDate를 이용해 바꾸시던가 해야합니다.

    그러나 자리수가 정확하다면 또한 TDateTimePicker컴포넌트를 사용하지 않을거라면

    쉽게하셔도 될겁니다.

    str := dbgrid1.Fields[13].AsSting;

    edit13.Text := copy(Str,1,4) +'-'+ copy(Str) +'-'+copy(Str,7,2);



    그래도 TDateTime형를 사용하시려거나 TDateTimePicker컴포넌트를 사용하시려면

    var

    Year, Month, Day: Word;

    str : string;

    begin

    str := dbgrid1.Fields[13].AsSting;

    Year := strToint(copy(str,1,4));

    Month := strToint(copy(str,6,2));

    Day := strToint(copy(str,9,2));

    edit13.Text := FormatDateTime('yyyy-mm-dd', EncodeDate(Year, Month, Day));