Studio
2020.10
false
OUT OF SUPPORT
Studio User Guide
Last updated Dec 20, 2023

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.
  4. Add an Assign activity to the Designer panel.
  5. In the Properties panel, in the To field, add the Today variable.
  6. 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.
  7. Add another Assign activity under the previous one.
  8. In the Properties panel, in the To field, add the LastTime variable.
  9. In the Value field, type Today.Subtract(Span). This is going to subtract the default value of the Span variable from the current date, stored in the Today variable.
  10. Add an Excel Application Scope activity under the last Assign one.
    Note: Use the Manage Packages feature to download the Excel activities, if you do not already have them installed.
  11. In the Properties panel, in the WorkbookPath 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.
  12. Add a Write Cell activity in the Excel Application Scope activity.
  13. In the Properties panel, in the Range field, type the coordinates of an Excel cell between quotation marks. In our case, "E3".
  14. In the Sheet Name field, type the name of the sheet in which you want to write. In our case, "Invoice". Note that if the sheet does not exist, it is going to be created.
  15. In the Value field, type LastTime.ToString. This transforms the value of the LastTime variable to a string and writes it to the coordinates previously given.

    The final project should look as in the following screenshot:



  16. Press F5. The automation is executed.
  17. 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.


Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.