A Dataverse user recently asked how to extract the date element from a datetime field.
This can be achieved relatively easily using some Python scripting in the Transform node as follows:
In the Tranform node's 'ConfigureFields' script enter the following (without the [Code] and [/Code] delimiters):
#Configure all fields from input 'in1' to be mapped
#to the corresponding fields on the output 'out1'
out1 += in1
## Define new output metadata for a date type field
out1.dateValue = datetime.date
where 'dateValue' is the name of the new field that will hold the extracted date value.
Then in the 'ProcessRecords' script enter the following (again without the delimiters):
#Copy all fields from input 'in1' to the corresponding output fields
#in output 'out1'. Copies the values of the fields that have been setup
#in the mapping defined in the ConfigureFields property
out1 += in1
if fields['InputField'] is Null:
out1.dateValue = Null
out1.dateValue = fields['InputField'].date()
where InputField is the name of the field containing the datetime values (the apostrophes are required around the name).
As a generalization of this approach, the attached community custom library node attached below can be used to extract the date element from a specified datetime field and output this in a different date type field.
I hope you find it useful!
You will need Dataverse 3.1.6 or later to import the custom library node. When the node has been imported you will find it in the 'Aggregation and Transformation' category of the node library.
Please note: This is a Community custom library node so it is not part of the Dataverse product and is not covered by the Lavastorm support policy.
Please sign in to leave a comment.