Data360 Analyze

 View Only
  • 1.  Extract the Month from Date

    Employee
    Posted 11-04-2019 14:46

    While cleaning up some superseded nodes, I came across one that is extracting the Month from a Date field.  How is this done in Data3Sixty?  

    Mon = month('Original')
    emit *, Mon

    Do I need to put this in Python and insert it into a Transform node?

     

    Thanks

    Mike

     



  • 2.  RE: Extract the Month from Date

    Employee
    Posted 11-04-2019 15:31

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Hey Mike, presuming that the field Original is already of type date you can just do this in a Calculated Fields node. The same would work in a Transform too. Same can be said for extracting year or day values.

    https://www.w3schools.com/python/python_datetime.asp



  • 3.  RE: Extract the Month from Date

    Employee
    Posted 04-30-2020 21:55
    import datetime
    
    a = '2010-01-31'
    datee = datetime.datetime.strptime(a, "%Y-%m-%d")
    
    
    datee.month
    Out[9]: 1
    
    datee.year
    Out[10]: 2010
    
    datee.day
    Out[11]: 31


    Python datetime module supplies classes for manipulating dates and times.


  • 4.  RE: Extract the Month from Date

    Employee
    Posted 05-01-2020 04:51

    Just to clarify the above comment in the context of using Python scripting in the Transform node to extract elements of date-type field, and to relate it back to the original question:

    The presumption is that the input data field 'Original' is a date type field - hence it is not necessary to parse the input data using the strptime() function. The Tranform node automatically imports the datetime module so it is not necessary to include this in your script.

    The following script extracts the month element (and the corresponding day and year elements) and outputs. Note that your Python script must handle Null values if there is a possibility that they may occur in the data (unlike when using the Calculate Fields node as described by Gerry - as the node provides defaults for Null date values).

     

    The resultant output is: