Extract the Month from Date
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
-
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
-
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:
Please sign in to leave a comment.
Comments
3 comments