# Comparing Stop/Start Dates and Times with LLTK

Lab scientists need to record both a start and stop date/time for an incubation. As a second evaluation of how many hours the incubation lasted, the scientists want BaseSpace Clarity LIMS to calculate the elapsed time.

The Lab Logic Toolkit *evaluateDynamicExpression* script can compare date/time entries and calculate elapsed hours. As *Date* fields in the LIMS do not display the required time component for this calculation, *Text* fields are needed.

The bash command uses a 'Date' function to convert the *Text* date/time entries into dates, and also uses a 'getTime' method to convert those dates into milliseconds since 1 January 1970 00:00:00 UTC. The difference between the two converted entries is then changed from milliseconds to hours.

## Example

1. Create a step level *Text* field for the *Start Date/Time*.
   * In this example, the field is named *Incubation Start yyyy-mm-dd hh24:mi*. The format is included in the name to assist the scientist entering the date/time.
2. Create a step level *Text* field for the *Stop Date/Time*.
   * In this example, the field is named *Incubation Stop yyyy-mm-dd hh24:mi*.
3. Create a step level *Numeric* field for the *Incubation Hours*. Set your preferred decimal place limit.
4. Create an automation and enter the following command line (if you have used different field names, edit the example command line to match):

   <pre class="language-markup" data-overflow="wrap"><code class="lang-markup">bash -l -c "/opt/gls/clarity/bin/java -jar /opt/gls/clarity/extensions/ngs-common/v5/EPP/ngs-extensions.jar -i {stepURI:v2} -u {username} -p {password} script:evaluateDynamicExpression 
   -exp 'step.::Incubation Hours:: = (Date.parse(::yyyy-mm-dd H:m::, step.::Incubation Stop yyyy-mm-dd hh24:mi::).getTime() - Date.parse(::yyyy-mm-dd H:m::, step.::Incubation Start yyyy-mm-dd hh24:mi::).getTime()) / (1000*60*60)' -log {compoundOutputFileLuid0}"
   </code></pre>
5. Set the automation to be triggered by a button on the step. This allows the scientist to enter/edit the *Start* and *Stop Date/Time* before the elapsed hours are calculated.

   > ℹ Adjustment for the *Start/Stop* events taking place over the 'daylight savings change events' is not included in this example.

**If you want to use a button to populate a Text field with the current date/time, then use:**

{% code overflow="wrap" %}

```markup
bash -l -c "/opt/gls/clarity/bin/java -jar /opt/gls/clarity/extensions/ngs-common/v5/EPP/ngs-extensions.jar -i {stepURI:v2} -u {username} -p {password} script:evaluateDynamicExpression -exp 'step.::Formulation:: = new Date().getDateTimeString()' -log {compoundOutputFileLuid0}"
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.claritylims.illumina.com/integration-toolkits/lltk/lltk-lab-logic-toolkit-script-examples/lltk-comparing-stop-start-dates-and-time-with-lltk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
