Transforms a string representing an amount of time into duration type. The input string must follow a specific format to be transformed. The following table lists the accepted input formats and their corresponding outputs in duration type:
|Type||Input (string)||Output (duration)||Example|
|Days||(0...n) day(s)||(0...n)d||1 day → 1d|
|Hours||(0...n) hour(s)||(0...23)h||15 hours → 15h|
|Minutes||(0...n) minute(s) / min||(0...59)m||45 min → 45m|
|Seconds||(0... n) second(s) / sec||(0...59)s||50 seconds → 50s|
|Milliseconds||(0...n)||(0...999)||300 → 300|
Note that milliseconds have no symbol representation, so the string will be simply transformed to duration data type, with no modification.
You can combine different amounts of time in your string and convert them into a duration. For example, if you enter 2 days 10 hours 30 minutes, it will be transformed into 2d10h30m. When you enter several amounts of time in a single string like this, separate them using blank spaces as in the example. Commas and other symbols are not accepted.
How does it work in the search window?
Select Create column in the search window toolbar, then select the Duration operation. You need to specify one argument:
The data type of the values in the new column is duration.
The examples in this article use values in a data table generated from this CSV file. If you want to try the example for yourself, download the file and upload it to your domain clicking Data upload in the navigation pane. Name the new table
my.upload.sample.data and select Current date as Date parsing type. Learn more about uploading data in Uploading log files.
After receiving the confirmation message, you can access the table from the Finder, selecting my → upload → sample → data. When you upload data from a file, all the information is included in a single column called message. To split the values into different columns, you can use the Split operation. Click Toggle Query Editor in the search window toolbar and paste the following LINQ query to save time:
select split(message, ";", 4) as durationStrings
my.lookuplist.conversion table, we want to transform the strings representing durations in the Duration strings column into duration data type. To do it, we will create a new column using the Duration operation.
The arguments needed to create the new column are:
- Duration - Duration strings column
Click Create column and you will see the following result:
How does it work in LINQ?
Use the operator
as... and add the operation syntax to create the new column. This is the syntax for the Duration operation:
You can copy the following LINQ script and try the above example on the
from my.upload.sample.data select split(message, ";", 4) as durationStrings select duration(durationStrings) as duration