This topic provides code samples of how to work with dates.
-
Gets the current date in the format MM/dd/yyyy HH:mm:ss
myCurrentDate = DateTime.Now
-
Parses string to DateTime, this only works if the pattern of the string matches your local date format
myDateTime = DateTime.Parse("02/25/1956")
-
Parses string to DateTime, this works even if the pattern of the string differs from your local date format
myCultureInfo = System.Globalization.CultureInfo.GetCultureInfo("de-DE") AND myDateTime = DateTime.Parse("25.02.1956", myCultureInfo)
-
Adds 3 hours to the current date
myDateTime = DateTime.Now.AddHours(3)
-
Subtracts 5 minutes from the current date
myDateTime = DateTime.Now.AddMinutes(-5)
-
Converts a double to a DateTime, using midnight December 30, 1899 as the base date)
yourStringAsDate = DateTime.FromOADate(Convert.ToDouble(dateAsString))