Liquid Studio 2021
Data Mapping / Data Mapper Functions / By Category / Date Time / Millisecond
In This Topic
    Millisecond
    In This Topic

    Function Name
    Millisecond
    Category
    DateTime
    Icon
    Millisecond
    Description
    Retrieve the millisecond portion of a DateTime value
    Inputs
    DateTime DateTime value to retrieve millisecond from
    Outputs
    Millisecond Millisecond value from DateTime input
    Properties
    None -

    Usage

    The Data Mapper DateTime Millisecond function returns the millisecond portion of a DateTime value. Many applications use DateTime values to record information about events, for example to process data such as weather incidents. It is often necessary to retrieve particular portions of a DateTime value, such as the millisecond, or to separate the DateTime into its component parts for the target application. To apply the DateTime Millisecond function, use the following process:

    Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using weather_source.xsd, an XML Schema Definition inferred from the following source:

    Source XML
    Copy Code
    <events>
     <weather_event>
      <incident_type>Tidal Wave</incident_type>
      <severity>5</severity>
      <recorded>2005-10-23T08:20:45.57</recorded>
     </weather_event>
     <weather_event>
      <incident_type>Hurricane</incident_type>
      <severity>9</severity>
      <recorded>2007-09-14T11:40:12.44</recorded>
     </weather_event>
    </events>
    

    For our target schema we will be using weather_alt_target.xsd, inferred from the following XML:

    Target XML
    Copy Code
    <weather>
     <incident type="lightning" severity="7">
      <min>12</min>
      <sec>31</sec>
      <mil>325</mil>
     </incident>
     <incident type="tornado" severity="10">
      <min>23</min>
      <sec>45</sec>
      <mil>778</mil>
     </incident>
    </weather>
    

    The data models weather events, including the DateTime for when an incident was recorded. Let's assume that in this case we want to map the millisecond within the second and minute that each event occurred. We will map all three parts of the DateTime to dedicated elements in the target as above. Here is the Data Mapper with Source and Target imported:

    Data Mapper Source and Target

    Drag the DateTime Millisecond function from the Component Palette into the mapping area:

    Millisecond Component

    Millisecond Transform Added

    The Millisecond function takes a single input, the DateTime in question, giving an output comprising the millisecond portion. The input should be connected to the source item, which will normally be an item in the XML Reader. The output should be connected to the target item, whether an item in the XML Writer or another component in the Mapper, for example if you plan on using the millisecond value to sort or filter the data.

    Connect the Millisecond function input to the "recorded" output in the XML Reader and the Millisecond output to the "mil" input in the XML Writer.

    Millisecond Mapped

    Now let's do the same for the minute portion of the DateTime. Drag a Minute component onto the Mapper, connecting its input to the "recorded" output in the XML Reader and its output to the "min" input in the XML Writer.

    Minute Added

    Do the same for the Second function now, connecting it to the "recorded" output in the XML Reader and the "sec" input in the XML Writer.

    Second Added

    Finally, connect the remaining inputs and outputs:

    Input and Output Connections Mapped

    We can now execute the transform by pressing Shift-F5 or the Execute button (Execute). The transform is applied and the file we selected as output opens in the editor:

    Output XML
    Copy Code
    <weather>
     <incident type="Tidal Wave" severity="5">
      <min>20</min>
      <sec>45</sec>
      <mil>570</mil>
     </incident>
     <incident type="Hurricane" severity="9">
      <min>40</min>
      <sec>12</sec>
      <mil>440</mil>
     </incident>
    </weather>
    

    The output contains the millisecond portion of each DateTime value for a single incident, represented as a number between 0 and 999, along with the minute and second data in each case.

    If you pass a value to the Millisecond function that is not a DateTime, the Mapper will attempt to parse it. If you pass the Millisecond function a DateTime value which does not contain a millisecond portion, the function will output a value of 0 by default.

    This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

    See Also