Function Name |
Day | ||
Category |
DateTime | ||
Icon |
|||
Description |
Retrieve the day portion of a DateTime value | ||
Inputs |
|
||
Outputs |
|
||
Properties |
|
The Data Mapper DateTime Day function returns the day portion of a DateTime value. Many applications use DateTime values to record information about events, for example retail or other account transactions. It is often necessary to retrieve particular portions of a DateTime value, such as the day, or to separate the DateTime into its component parts for the target application. To apply the DateTime Day 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 sales_source.xsd, an XML Schema Definition inferred from the following source:
Source XML |
Copy Code
|
---|---|
<sales> <purchase> <sale_id>9099879823</sale_id> <item_ref>ab65gh7hh7</item_ref> <customer_id>34522</customer_id> <transaction>2003-01-20T07:15:32.42</transaction> </purchase> <purchase> <sale_id>2390865748</sale_id> <item_ref>g7hy65tfd3</item_ref> <customer_id>12009</customer_id> <transaction>2007-06-12T23:35:10.09</transaction> </purchase> <purchase> <sale_id>8250987123</sale_id> <item_ref>d4rf54r0op</item_ref> <customer_id>28769</customer_id> <transaction>2006-11-27T17:20:09.88</transaction> </purchase> </sales> |
For our target schema we will be using sales_alt_target.xsd, inferred from the following XML:
Target XML |
Copy Code
|
---|---|
<transactions> <sale id="8987612312" item="y6yt5i93e4"> <cust_id>14398</cust_id> <day>20</day> <month>10</month> </sale> <sale id="2090176549" item="i8u7b45f7y"> <cust_id>23112</cust_id> <day>12</day> <month>8</month> </sale> <sale id="2819283722" item="y6yt5i93e4"> <cust_id>34309</cust_id> <day>9</day> <month>6</month> </sale> </transactions> |
The data models retail transactions, including the DateTime for when a sale was made. Let's assume that in this case we want to map the day and month during which each transaction took place, perhaps for marketing purposes. We will therefore need to retrieve both the day and month values from the input DateTime value, mapping these two to separate elements in the target. Here is the Data Mapper with Source and Target imported:
Drag the DateTime Day function from the Component Palette into the mapping area:
The Day function takes a single input, the DateTime in question, giving an output comprising the day 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 Day value to sort or filter the data in terms of purchases made throughout the months in a year.
Connect the Day function input to the "transaction" output in the XML Reader and the Day output to the "day" input in the XML Writer.
Let's now map the month value as well. Drag a Month component from the DateTime section onto the Mapper. Connect it also to the "transaction" output in the XML Reader and to the "month" input in the XML Writer.
Now the Mapper will retrieve two values from each DateTime input in the source data. Each transaction will include elements for both the day and the month.
Finally, connect the remaining inputs and outputs:
We can now execute the transform by pressing Shift-F5 or the Execute button (). The transform is applied and the file we selected as output opens in the editor:
Output XML |
Copy Code
|
---|---|
<transactions> <sale id="9099879823" item="ab65gh7hh7"> <cust_id>34522</cust_id> <day>20</day> <month>1</month> </sale> <sale id="2390865748" item="g7hy65tfd3"> <cust_id>12009</cust_id> <day>12</day> <month>6</month> </sale> <sale id="8250987123" item="d4rf54r0op"> <cust_id>28769</cust_id> <day>27</day> <month>11</month> </sale> </transactions> |
The output contains indicators of the days and months during which each transaction was made, with day represented as a number between 1 and 31.