ToDate
The ToDate function attempts to convert its input to a date.
Syntax
ToDate ( value )
Remarks
The value parameter holds the value to be converted. If the value is a number, it will be interpreted as the number of nanoseconds since 1990. The value can also be a string in a recognized date format.
Recognized Date Formats
1. mm-dd-year hh:mn:ss.sf (e.g., 08-15-2011 9:18:24.123456789)
2. dd-mm-year hh:mn:ss.sf (e.g., 15-08-2011 9:18:24.123456789)
3. yearmmdd hh:mn:ss.sf (e.g., 20110815 9:18:24.123456789)
4. mon dd year hh:mn:ss.sf (e.g., Aug 15 2011 9:18:24.123456789)
5. dd mon year hh:mn:ss.sf (e.g., 15 Aug 2011 9:18:24.123456789)
6. year-mm-dd hh:mn:ss.sf (e.g., 2011-08-15 9:18:24.123456789)
NOTE: The computer’s locale settings are used to distinguish between format 1 and format 2.
NOTE: The formats above show separators commonly used for the specified format. However, any of the following separators can be used to separate the items in the date and time: / - ; : . T or a space.
mm = 2-digit month
dd = 2-digit day of the month
year = 4-digit year (If the century is omitted, its value will be assumed based upon the value of the decade.)
hh = 2-digit hours into day
mn = 2-digit minutes into hour
ss = 2-digit seconds into minute
sf = 9-digit fractional seconds up to nanoseconds resolution
mon = abbreviated month name
NOTE: Only English month name abbreviations are currently supported.
Example
Example #1
In the following example, DateTimeIn is a string variable in a recognized date format. This expression returns that value as a timestamp (e.g., if DateTimeIn is "Jan 01, 1990 01:01:01", the timestamp 1/1/1990 1:01:01 AM is returned):
ToDate("Server:CR1000.Public.DateTimeIn")
Example #2
The following example will add one hour to the timestamp:
ToDate(ToInt(TimeStamp(Server:CR1000.one_sec.temp_degf)+nsecPerHour))
Example #3
The following example takes YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND values that are stored in a Virtual data source and converts them to a timestamp:
ToDate($"" + "Virtual:values.YEAR" + $"-" + "Virtual:values.MONTH" + $"-" + "Virtual:values.DAY" + $" " + "Virtual:values.HOUR" + $":" + "Virtual:values.MINUTE" + $":" + "Virtual:values.SECOND")