Archive for Giugno 2nd, 2008

IsDate

CodeKeep C# Feed Giugno 2nd, 2008

Description: If you must do this at least use tryparse rather than try catch

Link: http://www.codekeep.net/snippets/92bafaf1-4c02-453c-b321-871badfc20a8.aspx

public static bool IsDate(Object obj)
{
	DateTime result;
	return DateTime.TryParse(obj.ToString(), out result);
}

IsDate

CodeKeep C# Feed Giugno 2nd, 2008

Description: Is Date

Link: http://www.codekeep.net/snippets/89d20018-d7c9-42e0-9d5d-7bd46b710975.aspx

#region method IsDate

        public static bool IsDate(Object obj)
        {
            string strDate = obj.ToString();
            try
            {
                DateTime dt = DateTime.Parse(strDate);
                if (dt != DateTime.MinValue && dt != DateTime.MaxValue)
                    return true;
                return false;
            }
            catch
            {
                return false;
            }
        }

        #endregion