Convert Time Format

jason_xiejason_xie Member Posts: 4 Contributor I
edited November 30 in Help

Hi All, 


I need some help with converting my time format. Within the dataset that I have, my time is in 24 hour format  eg. 19:00 and 00:00. I am trying to convert these times into 12 hour format where 19:00 would turn into 7:00pm and 00:00 would turn into 12:00am. 


I used Nominal to Date operator, and set the date type to time, date format to h:mm a, but it's giving me a cannot parse date error since 00:00 is an unparseable date. Any thoughts on solving this problem? 





  • sgenzersgenzer Administrator, Moderator, Employee, RapidMiner Certified Analyst, Community Manager Posts: 1,867  Community Manager

    hello @jason_xie - I really should defer to @Marco_Boeck on this as I know how much he likes working with dates and times. But does this help?


    <?xml version="1.0" encoding="UTF-8"?><process version="8.0.000-BETA">
    <operator activated="true" class="process" compatibility="8.0.000-BETA" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="generate_data_user_specification" compatibility="8.0.000-BETA" expanded="true" height="68" name="Generate Data by User Specification" width="90" x="45" y="85">
    <list key="attribute_values">
    <parameter key="datetime" value="date_now()"/>
    <list key="set_additional_roles"/>
    <operator activated="true" class="generate_attributes" compatibility="8.0.000-BETA" expanded="true" height="82" name="Generate Attributes" width="90" x="179" y="85">
    <list key="function_descriptions">
    <parameter key="datetime" value="date_add(datetime,5,DATE_UNIT_HOUR)"/>
    <operator activated="true" class="date_to_nominal" compatibility="8.0.000-BETA" expanded="true" height="82" name="Date to Nominal" width="90" x="313" y="85">
    <parameter key="attribute_name" value="datetime"/>
    <parameter key="date_format" value="dd/MM/yyyy HH:mm"/>
    <operator activated="true" class="nominal_to_date" compatibility="8.0.000-BETA" expanded="true" height="82" name="Nominal to Date" width="90" x="447" y="85">
    <parameter key="attribute_name" value="datetime"/>
    <parameter key="date_type" value="time"/>
    <parameter key="date_format" value="dd/MM/yyyy HH:mm"/>
    <connect from_op="Generate Data by User Specification" from_port="output" to_op="Generate Attributes" to_port="example set input"/>
    <connect from_op="Generate Attributes" from_port="example set output" to_op="Date to Nominal" to_port="example set input"/>
    <connect from_op="Date to Nominal" 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"/>


  • jason_xiejason_xie Member Posts: 4 Contributor I

    Thanks so much, seems like it works the best if the variable has both date and time information. In my case, I have date and time as 2 different variables and the best way to approach it is to concac these two variables together and convert the time format then.


    Would love to hear if  @Marco_Boeck[] has any other inputs on this issue.

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,762   Unicorn
    Have you tried concatenating them first and then applying the Nominal to Date operator? Concatenation can be done via the Generate Attribute operator or Generate Concatenation too.
  • Edin_KlapicEdin_Klapic Moderator, Employee, RMResearcher, Member Posts: 234  RM Data Scientist

    Hi @jason_xie,


    the format you were probably searching for was simply "hh:mm" and not "hh:mm a".

    The date format parameter within the Operator Nominal to Date needs to know what the Attribute looks like.This means if your Attribute does not have AM or PM, the conversion cannot work.

    If your string only has values like 00:00 then this setting will not work.


    By the way:

    Whereas the attribute types date / time / date_time are internally stored in milliseconds since 01/01/1970, the *visual* representation in RapidMiner is always of the format "MMM dd, yyyy hh:mm:ss a z" (e.g. Nov 20, 2017 1:16:53 PM CET).

    If you want to have a different visualization you can only convert the attribute to nominal using the Operator Date to Nominal or a conversion function within Generate Attributes (e.g. date_str_custom()).


    Best regards,

Sign In or Register to comment.