Nominal to Date e.g.'01:40PM' to 13:40
artdijk
New Altair Community Member
LS
How can I convert a set of nominal fields that are meant to be date/time field to time.
e.g. I have 01:40PM and this needs to be 13:40
e.g. 08:20AM and this needs to be 08:20
How can this be done ?
What processes should I use and with what kind of settings ?
Thanks
Arthur
How can I convert a set of nominal fields that are meant to be date/time field to time.
e.g. I have 01:40PM and this needs to be 13:40
e.g. 08:20AM and this needs to be 08:20
How can this be done ?
What processes should I use and with what kind of settings ?
Thanks
Arthur
Tagged:
0
Answers
-
Hello Arthur
you can use the operator "Nominal to Date". I suggest to read the extensive documentation of this operator available in the "help"-tab.
hope this was helpful,
steffen0 -
Hi,
But I tried to use nominal to date. This process did not include the AM or PM in the conversion. All AM times were converted correctly but the PM were 12 hours wrong.
Any suggestion on how to account for PM ?
Thanks
Arthur0 -
Hello Arthur
Here is an example. Feel free to ignore all operators except "Nominal to Date", the others are for creating the demonstration data.
Please reread the documentation of this operator available in help tab. In one line it says:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.0">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" expanded="true" name="Process">
<process expanded="true" height="431" width="547">
<operator activated="true" class="retrieve" expanded="true" height="60" name="Retrieve" width="90" x="31" y="65">
<parameter key="repository_entry" value="//Samples/data/Golf"/>
</operator>
<operator activated="true" class="generate_empty_attribute" expanded="true" height="76" name="create_time" width="90" x="45" y="210">
<parameter key="name" value="time"/>
<parameter key="value_type" value="polynominal"/>
</operator>
<operator activated="true" class="execute_script" expanded="true" height="76" name="set_time_values" width="90" x="179" y="210">
<parameter key="script" value="ExampleSet exampleSet = operator.getInput(ExampleSet.class); int counter = 1; for (Example example : exampleSet) { 	if(Math.pow(-1,counter) == 1){ example["time"] = "08:10AM"; }else{ 	 example["time"] = "08:10PM"; } counter++; } return exampleSet;"/>
</operator>
<operator activated="true" class="generate_copy" expanded="true" height="76" name="Generate Copy" width="90" x="313" y="210">
<parameter key="attribute_name" value="time"/>
<parameter key="new_name" value="transformed_time"/>
</operator>
<operator activated="true" class="nominal_to_date" expanded="true" height="76" name="Nominal to Date" width="90" x="447" y="75">
<parameter key="attribute_name" value="transformed_time"/>
<parameter key="date_type" value="time"/>
<parameter key="date_format" value="h:mma"/>
</operator>
<connect from_op="Retrieve" from_port="output" to_op="create_time" to_port="example set input"/>
<connect from_op="create_time" from_port="example set output" to_op="set_time_values" to_port="input 1"/>
<connect from_op="set_time_values" from_port="output 1" to_op="Generate Copy" to_port="example set input"/>
<connect from_op="Generate Copy" from_port="example set output" to_op="Nominal to Date" to_port="example set input"/>
<connect from_op="Nominal to Date" from_port="example set output" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
The "trick" is to construct a parsing statement instead of using only those available.
a: am/pm marker; Text; example: PM
hope this was helpful,
steffen
0