datetime from string c# code example
Example 1: c# string to datetime
string iDate = "05/05/2005";
DateTime oDate = Convert.ToDateTime(iDate);
MessageBox.Show(oDate.Day + " " + oDate.Month + " " + oDate.Year );
Example 2: c# date
using System;
class Test {
static void Main() {
//print current datetime
Console.WriteLine (DateTime.Now.ToString());
//make a custom datetime
DateTime dt = new DateTime(2018, 7, 24);
Console.WriteLine (dt.ToString());
}
}
Example 3: string to datetime c#
DateTime.TryParse(stringDate, out DateTime date);
//date variable type is DateTime
Example 4: C# string to datetime
DateTime myDate = DateTime.ParseExact("2009-05-08 14:40:52,531", "yyyy-MM-dd HH:mm:ss,fff",
System.Globalization.CultureInfo.InvariantCulture);
Example 5: convert str to datetime
import datetime
# str value "Apr 2, 2019" convert into any format.
datetime.datetime.strptime(
Example 6: datetitime contrusctor c#
public struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable, System.Runtime.Serialization.ISerializable