We recommend switching to the latest versions of Edge, Firefox, Chrome or Safari. Using Internet Explorer will result in a loss of website functionality.

Extract the Month from Date

Comments

3 comments

  • Avatar
    Gerry Mullin

    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

    0
    Comment actions Permalink
  • Avatar
    warrenfelsh
    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.
    0
    Comment actions Permalink
  • Avatar
    Adrian Williams

    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:

    0
    Comment actions Permalink

Please sign in to leave a comment.