Subscribe

UiPath Studio

The UiPath Studio Guide

Date and Time Variables

The date and time variable is a type of variable that enables you to store information about any date and time. This type of variable can be found in the Browse and Select a .Net Type window, under the System namespace System.DateTime. For more information, see Browsing for .Net Variable Types.

For example, they can be used to append dates to invoices or any other documents you may be working with and are time-sensitive.

Example of Using a Date and Time Variable

To exemplify how you can work with a date and time variable, we are going to build an automation that gets the current date and time, subtracts a specific amount of time and writes the result to a Microsoft Excel spreadsheet.

  1. Create a new sequence.
  2. Create two DateTime variables, Today and LastTime.
  3. Create a TimeSpan variable, called Span, and in the Default field type 1.02:10:04.

📘

Note:

The default value attributed to theSpan variable uses the day.hh:mm:ss format.

  1. Add an Assign activity to the Designer panel.
  2. In the Properties panel, in the To field, add the Today variable.
  3. In the Value field, type Now. This gives you the date and time when the project is executed, in the dd/MM/yyyy and hh:mm:ss formats.
  4. Add another Assign activity under the previous one.
  5. In the Properties panel, in the To field, add the LastTime variable.
  6. In the Value field, type Today.Subtract(Span). This is going to subtract the default value of the Span variable from the current date and time, stored in the Today variable.
  7. Add an Excel Process Scope activity under the last Assign one. This activity opens or reuses Excel processes, loads the Excel project settings, and applies them to the associated Excel file.
  8. Add a Use Excel File activity inside the Excel Process Scope activity.

📘

Note:

Use the Manage Packages feature to download the Excel activities, if you do not already have them installed.

  1. In the Workbook path field, type the path of the Excel file you want to write to, between quotation marks. In our case, "%HOMEPATH%\Desktop\urgent_invoice.xlsx".

📘

Note:

If the file does not exist at the provided path, it is going to be created.

  1. Add a Write Cell activity in the Use Excel File activity.
  2. In the What to write field, type LastTime.ToString. This transforms the value of the LastTime variable to a string and writes it to the coordinates previously given.
  3. On the right side of the Where to write field, select Plus plus buttonplus button > Excel > Indicate in Excel.
  4. Inside the Excel file, indicate the cell in which you want to write (in our case, "E3"). Click Confirm after indicating the cell.
    The final project should look as in the following screenshot:
586586
  1. Press F5. The automation is executed.
  2. Navigate to your Excel file and double-click the cell in which you added the date. Note that the time and date information is displayed in the cell you pointed towards.
11271127

Download example

Updated about a month ago


Date and Time Variables


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.