Data360 Analyze

 View Only
  • 1.  Combine Date & Time Fields

    Employee
    Posted 04-15-2020 11:42

    I have two fields in a data source that I want to combine. One is a date and the other is a time. Here's what I have and what I want to accomplish:

    CURRENT FIELDS

    • event_date (format = 04/15/2020)
    • event_time (format = 17:44)

    OBJECTIVE

    • event_date_time (format = 2020-04-15 17:44:00)

    Any help would be appreciated.

    Thanks!



  • 2.  RE: Combine Date & Time Fields

    Employee
    Posted 04-16-2020 03:49

    You do not state the technical data type of the two fields. However, as you state the format I'm assuming both of the fields have a string or unicode data type, e.g. they are similar to this when viewed in the Data Viewer:

     

    The simplest way is to use the Modify Fields node to convert the event_date field to date type and the event_time field to a time type:

     

    Resulting in the following:

     

    Note that you will need to select the appropriate format for the ev_date from the suggested format list:

     

    In the case of the ev_time field the suggestions list does not contain the HH:MM format so you will need to select the HH:mm:ss format and then edit the format statement to remove the seconds element.

     

    The Calculate Fields node can then be used to derive a datetime data type field from the date and time fields. In this case the expression utilizes the datetime.datetime.combine() function:

     

    The ev_datetime variable has a datetime data type. You can then use another expression to create the string representation of the datetime value using the str() function, resulting in the following:

     

     

    If require, the above transformations can also be achieved (in a more long-hand way) using the Transform node:

    Note that you either need to ensure there are no Null values in the event_date and event_time fields or include appropriate code to handle the situation where either field is Null in a record.

     



  • 3.  RE: Combine Date & Time Fields

    Employee
    Posted 04-16-2020 07:48

    Thanks Adrian. That worked great!