Get action in Datetime

The Get action in the Datetime package retrieves the information such as year, month, hour, minute, second and so on from the given Datetime value and stores the result in a variable

To get a value from a Datetime variable, do the following:
  1. Double-click or drag the Get action from the Datetime package in the Actions palette.
  2. Select either the Datetime or Variable tab from the Date time variable to get the selected value field:
    • Datetime: Select the date, time, and timezone values from the dropdown.
    • Variable: Select a Datetime variable.
  3. In the Datetime value to get field, choose from the following options to retrieve a specified date and time value:
    • Day of month: Retrieves the day of the month
    • Day of week: Retrieves the day of the week
    • Day of year: Retrieves the day of the year
    • Length of month: Total number of days in a month
    • Length of year: Total number of days in a year (365 or 366 days, if leap year)
    • Hour: Retrieves the hour(s)
    • Minute: Retrieves the minute(s)
    • Month: Retrieves the month
    • Second: Retrieves the second(s)
    • Year: Retrieves the year
  4. Select the number variable from the Assign the output to a variable field to assign the output.

Example of using Get action in an automation

In this example, you will create an automation that retrieves the specified date and time value from a Datetime variable and stores the output in a variable.

Procedure

  1. Create a bot.
    1. On the left panel, click Automation.
      A list of available bots and forms is displayed.
    2. Click Create a bot.
    3. Enter the bot name: Datetime_Get.
    4. Click Create and Edit.
  2. Create the following user-defined variables using the Create variable (+) icon at the top of the Variables menu.
    Variable name Variable type Value
    invoiceDate Datetime Value 4/12/2023 10:45 AM GMT (UTC+0:00) GMT
    result Number 0
  3. Double-click or drag the Get action from the Datetime package in the Actions palette.
  4. In the Date time variable to get the selected value field, select invoiceDate variable.
  5. Select Day of month option from the Datetime value to get field.
  6. In the Assign the output to a variable field, select result.
  7. To print the value, double-click or drag the Message box action. In the Enter the message to display field, enter DAYOFMONTH: $result.Number:toString$.

    To see the output value, convert the Number variable to a String variable

  8. Click Save and then Run.
    The output is displayed as:

    Retrieves the day of the month

  9. Double-click or drag the Message box action. In the Enter the message to display field, enter the following expression:
    Note: When you enter the expression in the Enter the message to display field, ensure you enter the Get ("") expression parameters in uppercase.
    
    
    DAYOFYEAR: $invoiceDate.Datetime:get("DAYOFYEAR").Number:toString$
    DAYOFWEEK: $invoiceDate.Datetime:get("DAYOFWEEK").Number:toString$
    
    DAYOFMONTH: $invoiceDate.Datetime:get("DAYOFMONTH").Number:toString$
    MONTH: $invoiceDate.Datetime:get("MONTH").Number:toString$
    YEAR: $invoiceDate.Datetime:get("YEAR").Number:toString$
    
    HOUR: $invoiceDate.Datetime:get("HOUR").Number:toString$
    MINUTE: $invoiceDate.Datetime:get("MINUTE").Number:toString$
    
    LENGTHOFMONTH: $invoiceDate.Datetime:get("LENGTHOFMONTH").Number:toString$
    LENGTHOFYEAR: $invoiceDate.Datetime:get("LENGTHOFYEAR").Number:toString$
  10. Click Save and then Run.
    The output is displayed as:

    Retrieves the date time output in a message box