Tell me how to correct the mistake.
I am trying to convert the string to the correct format, but it does not work for me.
Text = "9/21/2004"
 DateTime d1 = DateTime.ParseExact(text.ToString(), "MM/dd/yyyy", null);
 return (T)Convert.ChangeType(text, underlyingType);
The full method:
public static T To<T>(this object text)
        {
            if (text == null) return default(T);
            if (text.Equals(DBNull.Value)) return default(T);
            if (text is string) if (string.IsNullOrWhiteSpace(text as string)) return default(T);
            var type = typeof(T);
            if(type.ToString() == "QuantLib.Date")
            {
                var dt = (DateTime)text;
                QuantLib.Date date = new QuantLib.Date((int)dt.ToOADate());
                return (T)Convert.ChangeType(date, type);
            }
            var underlyingType = Nullable.GetUnderlyingType(type) ?? type;
            DateTime d1 = DateTime.ParseExact(text.ToString(), "dd/MM/yyyy", null);
            return (T)Convert.ChangeType(d1, underlyingType);
        }
        public static T ToDatetime<T>(this QuantLib.Date date)
        {
            DateTime dt = Convert.ToDateTime(date.month() + " " + date.dayOfMonth().ToString() + ", " + date.year().ToString());
            var type = typeof(T);
            if (type == typeof(string))
                return (T)Convert.ChangeType(dt.ToShortDateString(), typeof(T));
            else
                return (T)Convert.ChangeType(dt, typeof(T));
        }
 
     
    