Posted On: Jan 21, 2021

We are excited to announce that AWS IoT SiteWise now supports date and time functions, and global time zones for use in metric and transform computations in the AWS IoT SiteWise asset model. You can now use date and time expressions to retrieve the current timestamp of equipment data in UTC (Coordinated Universal Time) or in your local time zone, construct timestamps given input parameters such as year, month, day of the month and time, and extract different time fields such as year or month given a specific timestamp value. The date and time functions supported by AWS IoT SiteWise are listed below.

Get current time - AWS IoT SiteWise now has time functions that allow you to extract current timestamps in two ways.
now() - You can use this function to retrieve time in epoch format or the number of seconds elapsed from Jan 1, 1970 12:00 am UTC.
timestamp() - You can use this function to retrieve the timestamp, in UTC epoch seconds, of the input message for transforms and the current window end timestamp for metrics.

Extract local time - localtime (epoch_seconds, timezone)
You can use this function to represent asset data from different time zones. Local time zones can be constructed either by specifying time zone prefixes ('UTC', 'CET'), or the timezone offset in hours ('UTC+01:00'). In a sample customer use case, an automotive manufacturer has plants and equipment located in Turkey, with data recorded in UTC. The manager can extract time in the local time zone in a SiteWise formula expression as localtime(timestamp(), ‘TRT’), where TRT is a pre-defined prefix for Turkey timezone, which can later be used to visualize data in local time zones. For a list of supported time zones, visit AWS IoT SiteWise Supported Time Zones.

Extract time fields - year(), mon(), yday(), mday(), wday(), hour(), minute(), sec()
You can use these functions to extract different time components (year, month, day of the year, day of the month, day of the week, hour, minute, second) from a local time object. As an example, a plant floor manager of a medical devices company located in Oregon wants to compute average productivity on each day of the week. The manager can define a metric as productivity_Monday=if(timestamp().localtime('PST').wday().eq(1), avg(productivity), none), which can later be used for comparing day-wise productivity. The wday() function returns the day of the week in an integer format 0-6, with 0 representing Sunday.

Construct time - mktime()
You can use this function to construct UTC epoch seconds (floating point) from the human-readable date format of year, month, day of month, etc. For example, if you want to represent a specific date and time, say January 19, 2021 4:31:39 UTC in epoch seconds, you can use the mktime() function in the following format: mktime(‘UTC’, 2021, 1, 19, 4, 31, 39.00).

For a list of date and time functions and examples, visit AWS IoT SiteWise Expressions.

AWS IoT SiteWise is a managed service to collect, store, organize and monitor data from industrial equipment at scale. To learn more, please visit the AWS IoT SiteWise website or the developer guide. For a list of AWS IoT SiteWise supported regions, visit AWS Regions.