RE: [aus-dotnet] IsDate function


    [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
    • From: William Luu
    • Subject: RE: [aus-dotnet] IsDate function
    • Date: Tue, 21 Sep 2004 16:18:19 +1000

    Well, you could always try doing a DateTime.Parse(str) and catch the exception?
     
    private bool IsDate(string strDate)
    {
        bool isDate = false;
        try
        {
            DateTime.Parse(strDate);
            isDate = true;
        }
        catch (ArgumentNullException nullArg)
        {
                // you can do something here to tell user it was a null input etc...
            isDate = false;
        }
        catch (FormatException formatEx)
        {
            isDate = false;
        }
     
        return isDate;
    }
     
    Not sure if that's the best way, but that's certainly one way.

    --
    William Luu
    Project Developer
    The Grid Corporation

    -----Original Message-----
    From: Alastair Waddell [mailto:AliWaddell@xxxxxxxxxxxxxxx]
    Sent: Tuesday, 21 September 2004 4:04 PM
    To: dotnet@xxxxxxxxxxx
    Subject: [aus-dotnet] IsDate function
    Importance: High

    Does anybody have a better way of checking a string to see if it is a valid date?

     

     

    Ie ....

     

    Function CheckDate(_value as string) as Boolean

     

    Return IsDate(_value)

     

    End Function

     

    This is very slow if the input param is null

     

    A

     

     

     




    (Click here for more information on the aus-dotnet mailling list)