Working with Dates

  • myCurrentDate = DateTime.Now [retrieves the current date in the following format: MM/dd/yyyy HH:mm:ss]
  • myDateTime = DateTime.Parse("02/25/1956") [parses string to DateTime; works only if the pattern of the string resembles your local date format]
  • myCultureInfo = System.Globalization.CultureInfo.GetCultureInfo("de-DE") AND myDateTime = DateTime.Parse("25.02.1956", myCultureInfo) [parses string to DateTime; works also if the pattern of the string deviates from your local date format]
  • myDateTime = DateTime.Now.AddHours(3) [adds 3 hours to the current date]
  • myDateTime = DateTime.Now.AddMinutes(-5) [subtracts 5 minutes from the current date]
  • yourStringAsDate = DateTime.FromOADate(Convert.ToDouble(dateAsString)) [converts a double to a DateTime (midnight 30th December 1899 serves as base date)]
Was this article helpful?
0 out of 0 found this helpful