DateTime.TryParse() Method Example

Kundnani.Rt
Posted by Kundnani.Rt under C# category on | Points: 40 | Views : 1579
The code demonstrates how to use DateTime.TryParse() Method.

TryParse() returns the DateTime object as
out 
parameter.


static void Main(string[] args)
{
string myDate = "05-25-2012";

DateTime fromMyDate;

if (DateTime.TryParse(myDate, out fromMyDate))
{
Console.WriteLine("TryParse() Method Demo\n\n" + fromMyDate);
Console.WriteLine("\n\nConversion Succeeded...");
}
else
Console.WriteLine("Conversion failed...");

Console.Read();
}

Comments or Responses

Login to post response