.NET Framework
Contents
By .NET Framework I mean C# :D. In C#, converting a DateTime object to a String is by calling its ToString method. On the other hand, converting a String to a DateTime is by using either DateTime.Parse or DateTime.ParseExact.
Console.WriteLine(DateTime.Now.ToString()); // Output: 3/21/2015 5:50:43 AM Console.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy")); // Output: 21-Mar-2015 var dt = DateTime.Parse("19 Mar 2012"); // Works var dt1 = DateTime.Parse("19 03 2012"); // Exception, because my default the US Way var dt2 = DateTime.Parse("03 19 2012"); // Only works if your default culture has date format similar to German, e.g. Italy // Now we parse with custom format var dt3 = DateTime.ParseExact("19 03 2012", "dd MM yyyy", System.Globalization.CultureInfo.InvariantCulture) // Works
As we can see, we may pass the custom format to DateTime.ParseExact and DateTime.ToString. The symbols which we can use in the custom format is exactly the same as the symbols we use in MS SQL (please refer to the previous page).
Hopefully, converting between DateTime to String, vice-versa, would no longer a problem. You can always return here for a quick reference.
I hope it helps,
Cheers
loading...
About Hardono
Incoming Search
.net, c#, mssql, mysql, oracle