Find more posts tagged with
Regex worked pretty well. Going a step further what I wanted to achieve was to convert the english date into a german one so:
12/3/16 (mm/dd/yy) in 03.12.16
I replaced the "/" with dots and changed the order of day and month with the regex-replace. Now to further work with this date in excel it should be in the named format (above). Unfortunately it is in the format 3.12.16, thus the zeros are missing.
My question is how can I get the zeros in the date and if this way of achieving this is even good to do so, because I think this is somehow very complicated to just transform english date into a german one.
Thank you
Philipp
Hey,
i think its just another regex with Replace:
0(\d)
replace with
$1
Attached is a process doing it.
~Martin
<?xml version="1.0" encoding="UTF-8"?><process version="7.4.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.4.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data_user_specification" compatibility="7.4.000" expanded="true" height="68" name="Generate Data by User Specification" width="90" x="112" y="34">
<list key="attribute_values">
<parameter key="date" value=""03.12.16""/>
</list>
<list key="set_additional_roles"/>
</operator>
<operator activated="true" class="replace" compatibility="7.4.000" expanded="true" height="82" name="Replace" width="90" x="246" y="34">
<parameter key="replace_what" value="(\d+).(\d+).(\d+)"/>
<parameter key="replace_by" value="$2.$1.$3"/>
</operator>
<operator activated="true" class="replace" compatibility="7.4.000" expanded="true" height="82" name="Replace (2)" width="90" x="380" y="34">
<parameter key="replace_what" value="0(\d)"/>
<parameter key="replace_by" value="$1"/>
</operator>
<connect from_op="Generate Data by User Specification" from_port="output" to_op="Replace" to_port="example set input"/>
<connect from_op="Replace" from_port="example set output" to_op="Replace (2)" to_port="example set input"/>
<connect from_op="Replace (2)" 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>
Hi Philipp,
I suggest the usage of the Generate Attributes Operator and the built-in date conversion functions.
The following expression converts the nominal value "12/3/16" into the desired nominal output format "03.12.16".
date_str_custom(date_parse_custom("12/3/16","M/d/yy"),"dd.MM.yy")
Simply replace the string with the attribute name and you are set
Best regards,
Edin
Hi Philipp,
Within Generate Attributes everything between double quotes is interpreted as a string. So the function wants to parse the string Day (and not the attribute with the name Day) to a date which creates the error.
Assuming the value type of Day is nominal the solution would therefore be
date_str_custom(date_parse_custom(Day,"M/d/y
Best,
Edin
Hi Philipp,
Within Generate Attributes everything between double quotes is interpreted as a string. So the function wants to parse the string Day (and not the attribute with the name Day) to a date which creates the error.
Assuming the value type of Day is nominal the solution would therefore be
date_str_custom(date_parse_custom(Day,"M/d/y
Best,
Edin
Hey,
do you mean attribute order? If yes, reorder attributes is the operator. Or do you to sort a string?
~Martin