Convert.ToDateTime(Convert)
Converts data to a DateTime object.
Applies To
Description
Converts data to a DateTime object. This converts data types into DateTime objects. If a DateTime object is null and you try to display the object as text will result in a scripting error.
-
Numbers: any integer from 0 to 2359 will convert to a time in hours and minutes. Everything else will result in a null object.
-
Text: any text that resembles a date, time or combination will resolve to a DateTime object. Everything else will result in a null object.
-
Booleans, Arrays, and Objects: will evaluate to a null object.
Properties and Methods
Properties
-
.Day
-
.DaylightSavings
-
.DayOfWeek
-
.DayOfYear
-
.Hour
-
.ISOString
-
.LongDateString
-
.LongTimeString
-
.Minute
-
.Month
-
.Second
-
.ShortDateString
-
.ShortTimeString
-
.Year
Methods
-
.AddDays(Days)
-
.AddHours(Hours)
-
.AddMinutes(Minutes)
-
.AddMonths(Months)
-
.AddSeconds(Seconds)
-
.AddYears(Years)
-
.Compare(To)
-
.Copy()
-
.StringDayOfWeek([Culture])
-
.StringMonth([Culture])
Available
The .ToDateTime(Convert) method is available in:
-
15.03.016
-
All newer builds
Type
DateTime
Syntax
Convert.ToDateTime(Convert);
Parameters
|
Parameter |
Required |
Description |
|---|---|---|
| Convert | Yes | Any data type and value that converts to a DateTime object |
Example
Event.Form.MessageBox('Integer up to 2359 (1000): ' + Convert.ToDateTime(1000).LongTimeString +
'\nNegative Integer: ' + Convert.ToDateTime(-2) +
'\nText recognized as Date: ' + Convert.ToDateTime('10/05/2021').ShortDateString +
'\nText recognized as time: ' + Convert.ToDateTime('14:32:21').LongTimeString +
'\nBooleans: ' + Convert.ToDateTime(true) +
'\nArray: ' + Convert.ToDateTime([1, 2, 3]) +
'\nObject: ' + Convert.ToDateTime({}));
/*Expected System Prompt Display
Integer up to 2359 (1000): 10:00:00
Negative Integer: null
Text recognized as Date: 10/05/2021
Text recognized as time: 14:32:21
Booleans: null
Array: null
Object: null
*/