DateTime Class Methods List

‮tth‬ps://www.theitroad.com

Here are some common methods of the DateTime class with a brief description of what they do:

  1. now(): Returns a DateTime object representing the current date and time.

  2. date(): Returns a new DateTime object with the same year, month, and day, but with the time set to midnight.

  3. time(): Returns a new DateTime object with the same time, but with the date set to January 1, 1 (the minimum valid date in the .NET Framework).

  4. year(): Returns the year of the DateTime object.

  5. month(): Returns the month of the DateTime object.

  6. day(): Returns the day of the month of the DateTime object.

  7. hour(): Returns the hour of the DateTime object.

  8. minute(): Returns the minute of the DateTime object.

  9. second(): Returns the second of the DateTime object.

  10. dayofweek(): Returns the day of the week of the DateTime object.

  11. adddays(days): Returns a new DateTime object with the specified number of days added.

  12. addhours(hours): Returns a new DateTime object with the specified number of hours added.

  13. addminutes(minutes): Returns a new DateTime object with the specified number of minutes added.

  14. addseconds(seconds): Returns a new DateTime object with the specified number of seconds added.

  15. addmonths(months): Returns a new DateTime object with the specified number of months added.

  16. addyears(years): Returns a new DateTime object with the specified number of years added.

  17. subtract(other): Returns a TimeSpan object representing the difference between the current DateTime object and the specified DateTime object.

  18. tostring(format): Returns a string representation of the DateTime object using the specified format.

  19. parse(str, format): Converts the specified string representation of a date and time to its DateTime equivalent using the specified format.

  20. tryparse(str, dt): Converts the specified string representation of a date and time to its DateTime equivalent using the specified format, and returns a value indicating whether the conversion succeeded.