Q&A

  • 두날짜사이의 기간일수 구하는법좀갈켜주세요ㅠㅠ
2001-12-20에서 2001-11-20을 빼면 일수는 30 이렇게요



1  COMMENTS
  • Profile
    권대웅 2001.11.14 22:49
    초보 wrote:

    > 2001-12-20에서 2001-11-20을 빼면 일수는 30 이렇게요

    >



    //두날짜 사이 일수

    function DifferDays(FromDate, ToDate: TDateTime): Integer;

    var

    FDate, TDate : LongInt;

    begin

    FDate := trunc(FromDate);

    TDate := trunc(ToDate);

    Result := Abs(FDate - TDate);

    end;



    쿼리로는 이렇게...

    select convert(int, convert(datetime, '2001-10-10')) -

    convert(int,convert(datetime, '2001-9-10'))



    하거나 아니면..

    DATEDIFF() 함수를 쓰면 될 것 같네요!



    참고로 문자 -> 날자 형식으로 변환은

    function StringToDate(soDate : String) : TDateTime;

    var

    yy, mm, dd : Word;

    function delcchar(a,b : string) : string;

    begin

    while (pos(b,a) <> 0) do delete(a,pos(b,a),1);

    delcchar := a;

    end;



    begin

    soDate := DelCChar(soDate, ' ');

    soDate := DelCChar(soDate, '/');

    soDate := DelCChar(soDate, '-');

    soDate := DelCChar(soDate, '.');



    if Length(soDate) = 6 then begin

    soDate := copy(FormatDateTime('yyyy',now),1,2) + soDate;

    end;



    if Length(soDate) <> 8 then begin

    Result := 0;

    exit;

    end;



    yy := StrToInt(copy(soDate,1,4));

    mm := StrToInt(copy(soDate,5,2));

    dd := StrToInt(copy(soDate,7,2));



    try

    Result := EnCodeDate(yy,mm,dd);

    except

    Result := 0;

    exit;

    end;

    end;



    즐거운 하루 되세요!