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, you can get this information by using the DateTimeGet() functions. But you cannot set the date and time of the controller through AeroScript.

For instructions about how 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.

To get the date and time of the controller, use the DateTimeGet() function that follows. This function shows the date and time represented as the number of seconds since 00:00, Jan 1, 1970 UTC, which is also known as the “common epoch”.

function DateTimeGet() as integer

Gets the current time on the controller.

Returns

The number of seconds since the common epoch.

 

You can also get the date and time preformatted as a string. To do this, use the DateTimeGet() function overload that follows:

function DateTimeGet(ref $dateTimeString as string) as integer

Gets the current time on the controller.

Arguments

ref $dateTimeString  Output string representation of the current date and time.

Returns

The number of seconds since the common epoch.

The $dateTimeString argument is returned in the format given by the Default option of the DateTimeStringFormat enum. Refer to Table: DateTimeStringFormat Enum Options that follows for more information.

You can also get the date and time preformatted as a string in different formats. To do this, use the DateTimeGet() function overload that follows:

function DateTimeGet(ref $dateTimeString as string, $dateTimeStringFormat as DateTimeStringFormat) as integer

Gets the current time on the controller.

Arguments

ref $dateTimeString  Output string representation of the current date and time.

$dateTimeStringFormat  The format style to use to create the date and time string.

Returns

The number of seconds since the common epoch.

The value of the $dateTimeStringFormat argument changes the type of string format that the $dateTimeString argument outputs. These formats correspond to the DateTimeStringFormat enum options. Refer to the table that follows for more information.

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]

DateTimeGet Example

// 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)

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.

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.

function DateTimeExtractYear($dateTimeEpoch as integer) as integer

Extracts the year component from the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

The year component of the given date.

function DateTimeExtractMonth($dateTimeEpoch as integer) as integer

Extracts the month component from the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

The month component of the given date [1 - 12].

function DateTimeExtractDay($dateTimeEpoch as integer) as integer

Extracts the day component from the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

The day component of the given date [1 - 31].

function DateTimeExtractHour($dateTimeEpoch as integer) as integer

Extracts the hour component from the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

The hour component of the given date [0 - 23].

function DateTimeExtractMinute($dateTimeEpoch as integer) as integer

Extracts the minute component from the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

The minute component of the given date [0 - 59].

function DateTimeExtractSecond($dateTimeEpoch as integer) as integer

Extracts the second component from the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

The second component of the given date [0 - 59].

function DateTimeExtractDayOfWeek($dateTimeEpoch as integer) as integer

Extracts the day of the week from the day of the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

Integer representing the day of the week since Sunday. [0 - 6]

function DateTimeExtractDayOfYear($dateTimeEpoch as integer) as integer

Extracts the day of the year from the day of the given epoch time.

Arguments

$dateTimeEpoch  The number of seconds from the common epoch.

Returns

Integer representing the days since January 1 [0-365].

Custom Date Example

// 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)