请问有无函数检验一个日期是否有效,在线等待,谢谢~

解决方案 »

  1.   

    我只知道SQL Server里,有一个返回年龄的函数,DATEDIFF(yyyy, 出生日期,GETDATE(NOW))最后一个参数是返回当前系统日期和时间的一个函数.
    DELPHI中也能有类似这样的函数.
      

  2.   

    //判断字符串是否是有效日期类型
    function isdate(s:string):boolean;
    begin
     result:=false;
    try
      strtodate(s);
      result:=true;
    except
      on econverterror do
      result:=false;
    end;
    end;
      

  3.   

    Try
    Except不哦自己写字符串分析都能OK的http://lysoft.7u7.net
      

  4.   

    先判断是否数字,不是数字的话是否你定义的分割符,根据判断返回结果
    用try/except可以实现,不过调试代码时会异常,很烦
      

  5.   

    腊笔同志,你的函数不行
    楼上的两位,你们说的Try
    Except也不行,这个异常无法捕捉
      

  6.   

    你可能要自己判断,不符合的改为符合的...
    比如2004.03.03你把小数点去掉..换成20040303是FORMATDATE('YYYYDDMM'),可以设置程序日期都为那种格式的
      

  7.   

    why?
    function isdate(s:string):boolean;
    begin
     result:=false;
    try
      strtodate(s);
      result:=true;
    except
      on econverterror do
      result:=false;
    end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    if isdate('2004-9-31') then
      showmessage('是')
      else
      showmessage('否');
    end;日期分隔符换成“-”试下。
    自己写代码判断,麻烦。
      

  8.   

    to     function is 
    function isdate(s:string):boolean;
    begin
     result:=true;
    try
      strtodate(s);
    except
      on econverterror do
      result:=false;
    end;
    end;
      

  9.   

    一个日期?  楼主的意思是字符串还是TDateTime?
      

  10.   

    function IsRightDate(mInputDate: String): Boolean;
    begin
      try
        StrToDate(mInputDate);
        Result:=True;
      except
        Result:=False;
      end;
    end;
      

  11.   

    你把年月日分解出来,然后用下面的函数,如果无效则返回False。function TryEncodeDate(Year, Month, Day: Word; out Date: TDateTime): Boolean;
      

  12.   

    或者uses DateUtils;function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;
      

  13.   

    function isdate(s:string):boolean;
    begin
     result:=false;
    try
      strtodate(s);
      result:=true;
    except
      on e:exception do
      begin
       result:=false;
       showmessage(e.Message);
      end;
    end;
    end;
      

  14.   

    要直接实行.exe文件才可以catche