problem with System.Convert.ToDateTime

Last post 03-03-2004 8:56 AM by petesop1. 1 replies.

Sort Posts:

  • problem with System.Convert.ToDateTime

    03-03-2004, 5:50 AM
    • Contributor
      2,658 point Contributor
    • mp417
    • Member since 07-25-2003, 3:45 PM
    • Pune, India
    • Posts 549
    i want to check whether a variable contains date or not


    public static bool IsDate(string stringToTest)
    {
    System.DateTime datTest = System.DateTime.Now;

    bool bRtn = false;

    try {
    datTest = System.Convert.ToDateTime(stringToTest.ToString());
    bRtn = true;
    }
    catch(Exception exe) { bRtn = false ; }
    return bRtn;
    }


    if I pass 4.42 to IsDate() then exception occurs and it is returning false (that is what expected)

    but if I pass 5.09 to IsDate() then it is returning true (internally 5.09 getting converted to 5/9/2004)


    does anybody know how to solve this problem?

    I thought that converting value to Double might help

    please help me out of this..........

    for your information
    I am new to c#
    I know VB.net well

    thanx in advance
    mp417
    feed the creative machine
  • Re: problem with System.Convert.ToDateTime

    03-03-2004, 8:30 AM
    • Member
      660 point Member
    • petesop1
    • Member since 03-01-2004, 1:18 AM
    • Posts 132
    You could try using DateTime.Parse or DateTime.ParseExact and passing in the format of the date that you want to check for
    I could write a signature here, but who'd read it?
Page 1 of 1 (2 items)