DateTime Functions

If you want to use the date and time of a drive-based or a PC-based controller in your AeroScript programs and libraries, use the DateTimeGet() function. AeroScript also has several functions that you can use to get individual date and time components.

IMPORTANT: You cannot set the date and time of the controller with AeroScript. To set the date and time on drive-based controllers, refer to the methods in the Controller milestone of Machine Setup. For PC-based controllers, you must use the standard Windows menus.

DateTimeGet() Function and Overloads

When you use the DateTimeGet() function to get the date and time of the controller, the date and time are shown as the number of seconds since Jan 1, 1970 UTC, which is 00:00. This time format is known as the “common epoch”.

You can use the DateTimeGet() function overloads to get the date and time preformatted as a string. The overload has the ref $dateTimeString argument, which is returned in the Default format, as shown in the DateTimeStringFormat Enum Options table.

You can also use the DateTimeGet() function overload with the $DateTimeStringFormat argument to change the format of the string that is returned by the ref $dateTimeString argument. Refer to the table that follows for more information about the $DateTimeStringFormat argument options in the DateTimeStringFormat enum.

Table: DateTimeStringFormat Enum Options

Options Description

Default

To create the date and time string, use the format that follows:

[DayOfWeek] [YYYY]-[MM]-[DD] [HH]:[MM]:[SS] [TimeZone]

Iso8601Local

To create the date and time string, use the ISO-8601 Local format that follows:

[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS]

Iso8601Utc

To create the date and time string, use the ISO-8601 UTC format that follows:

[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS]Z

Iso8601UtcWithOffset

To create the date and time string, use the ISO-8601 UTC format with the UTC offset. It includes the formats that follow:

[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS]+[HH][MM]

OR

[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS]-[HH][MM]

Program Example: DateTimeGet

// Let's say the date is currently 2024-08-27, the time is currently 13:53:35,
// and the time zone on the controller is set to Eastern Daylight Time (EDT).
var $dateTimeString as string(250)

// The $dateTimeString variable will be set to "Tuesday 2024-08-27 13:53:35 EDT".
// The string reports "13" hours because this format reports the time based on
// the time zone of the controller (EDT).
DateTimeGet($dateTimeString, DateTimeStringFormat.Default)
AppMessageDisplay($dateTimeString)

// The $dateTimeString variable will be set to "2024-08-27T13:53:35".
// The string reports "13" because this format reports the time based on
// the time zone of the controller (EDT).
DateTimeGet($dateTimeString, DateTimeStringFormat.Iso8601Local)
AppMessageDisplay($dateTimeString)

// The $dateTimeString variable will be set to "2024-08-27T17:53:35Z".
// The string reports "17" hours because this format gets the time
// in Coordinated Universal Time (UTC).
DateTimeGet($dateTimeString, DateTimeStringFormat.Iso8601Utc)
AppMessageDisplay($dateTimeString)

// The $dateTimeString variable will be set to "2024-08-27T13:53:35-0400".
// The string reports "13" hours because this format reports the time based on
// the time zone of the controller (EDT).
// The offset of the time is "-0400", which is the difference between
// the controller's time zone (EDT) and Coordinated Universal Time (UTC) time.
DateTimeGet($dateTimeString, DateTimeStringFormat.Iso8601UtcWithOffset)
AppMessageDisplay($dateTimeString)

Time Zones

IMPORTANT: The names of time zones are different between the PC and Drive-based controllers.

To find the time zones that apply to your controllers:

  • For PC-based controllers, Windows has a default list of time zones. But this list might change based on the version of Windows that you are using. See Default Time Zones.
  • For drive-based controllers, see the Time Zones for Drive-Based Controllers section of Date and Time Configurations.

Custom Date and Time Operations

If you want to do date and time operations that are specific to your project or create your own custom date and time format, the AeroScript API has a set of functions that you can use to extract individual date and time components from the value that is returned by the DateTimeGet() function.

Program Example: Custom Date

// Let's say the date is currently 2024-08-27, the time is currently 13:53:35,
// and the time zone on the controller is set to Eastern Daylight Time (EDT).
var $customDate as string(256)

var $epoch as integer
var $day as integer
var $month as integer
var $year as integer

// Get the epoch time and extract the day, month, and year from it.
$epoch = DateTimeGet()
$day = DateTimeExtractDay($epoch)
$month = DateTimeExtractMonth($epoch)
$year = DateTimeExtractYear($epoch)

// Create your own custom date string by concatenating the day, month, and year.
// $customDate will be equal to "8/27/2024".
$customDate = IntegerToString($month) + "/" +
IntegerToString($day) + "/" + IntegerToString($year)
AppMessageDisplay($customDate)