Use the dates methods to use, extract, and evaluate dates in your
automations.
Compare methods
Method | Description |
Compare | Compares two instances of DateTime and returns whether the first
instance is earlier than, the same as, or later than the second
instance. |
Date | A new DateTime with the same date as DateTime value, and the time
value set to 12:00:00 midnight (00:00:00). |
Equals | Returns a value that indicates whether two DateTime objects, or a
DateTime instance and another object or DateTime, have the same
value. |
Convert methods
Method | Description |
Parse | Converts the string representation of a date and time to its
DateTime equivalent. |
ParseExact | Converts the specified string representation of a date and time
to its DateTime equivalent. The format of the string representation
must match a specified format or an exception occurs. |
TryParse | Converts the specified string representation of a date and time
to its DateTime equivalent and returns a value that indicates
whether the conversion succeeded. |
Extract methods
Method | Description |
Day | Gets the day of the month that is represented by this DateTime
instance. |
DayOfWeek | Gets the day of the week that is represented by this DateTime
instance. |
DayOfYear | Gets the day of the year that is represented by this DateTime
instance. |
DaysInMonth | Returns the number of days in the specified month and
year. |
Hour | Gets the hour component of the date that is represented by this
DateTime instance. |
IsDaylightSavingTime | Indicates whether this instance of DateTime is within the
daylight saving time range for the current time zone. |
IsLeapYear | Indicates whether the specified year is a leap year. |
Millisecond | Gets the milliseconds component of the date represented by this
DateTime instance. |
Minute | Gets the minute component of the date represented by this
DateTime instance. |
Month | Gets the month component of the date represented by this DateTime
instance. |
Second | Gets the seconds component of the date represented by this
DateTime instance. |
Ticks | Gets the number of ticks that represent the date and time of this
DateTime instance. |
TimeOfDay | Gets the time of day for this DateTime instance. |
Today | Gets the current date. |
WeekOfYear | Returns the week of the year that includes the date in the
specified DateTime value. |
Year | Gets the year component of the date represented by this DateTime
instance. |
Math methods
Method | Description |
Add | Returns a new DateTime that adds the value of the specified
TimeSpan to the value of this instance. |
AddDays | Returns a new DateTime that adds the specified number of days to
the value of this instance. |
AddHours | Returns a new DateTime that adds the specified number of hours to
the value of this instance. |
AddMilliseconds | Returns a new DateTime that adds the specified number of
millieseconds to the value of this instance. |
AddMinutes | Returns a new DateTime that adds the specified number of minutes
to the value of this instance. |
AddMonths | Returns a new DateTime that adds the specified number of months
to the value of this instance. |
AddSeconds | Returns a new DateTime that adds the specified number of seconds
to the value of this instance. |
AddTicks | Returns a new DateTime that adds the specified number of ticks to
the value of this instance. |
AddYears | Returns a new DateTime that adds the specified number of years to
the value of this instance. |
Subtract | Returns the value that results from subtracting the specified
time or duration from the value of this instance. |
Now methods
Method | Description |
Now | Gets a DateTime object that is set to the current date and time
on this computer, expressed as the local time. |
UtcNow | Gets a DateTime object that is set to the current date and time
on this computer, expressed as the Coordinated Universal Time
(UTC). |
String methods
Method | Description |
GetTimeStamp | Returns a formatted string with a timestamp. The default
timestamp format is yyyyMMddHHmmssfff. |
ToLongDateString | Converts the value of the current DateTime object to its
equivalent long date string representation. |
ToLongTimeString | Converts the value of the current DateTime object to its
equivalent long time string representation. |
ToShortDateString | Converts the value of the current DateTime object to its
equivalent short date string representation. |
ToShortTimeString | Converts the value of the current DateTime object to its
equivalent short time string representation. |
ToString | Converts the value of the current DateTime object to its
equivalent string representation. |
TimeZone methods
Method | Description |
ConvertTime | Converts a time to the corresponding time in the specified time
zone. |
ConvertTimeFromUtc | Converts a Coordinated Universal Time (UTC) to the time in the
specified time zone. |
ConvertTimeToUtc | Converts a date and time to Coordinated Universal Time
(UTC). |
FindTimeZone | Instantiates a new TimeZoneInfo object based on its
identifier. |
GetTimeZones | Returns a sorted collection of all the time zones about which
information is available on the local system. |
LocalTimeZone | Gets a TimeZoneInfo object that represents the local time
zone. |
TimeZoneToString | Returns the display name of the current TimeZoneInfo
object. |