You do not provide details of the error but there are probably a couple of issues with the above code. The first is that you do not reference the input field on the right hand side of the assignment. Secondly, the code will not handle the situation where there are Null values in the input data.
As an example of using a Transform node for the conversion, assume the input data is as follows:
The ConfigureFields script would comprise:
In this case, as the output formatted date string field is to have the same name as the input field (which is a Date type), it is necessary to remove the existing field from the output data. The metadata for a new unicode string field can then be added.
The ProcessRecords script would perform the conversion of the values:
The code tests whether the input value is Null and, if it is, sets the output value to Null. Otherwise, the input Date value is converted to the formatted string.
You can also achieve the above in a simple and code-free manner using the Modify Fields node.
The output Type is configured to be unicode and the required string format is selected from the options listed in the Format attribute (you can also enter/edit the format pattern if a custom format is required). The Modify Fields node automatically handles any Null values in the data.
The attached data flow contains the above example (Analyze v.3.6.x required).
Attached files
Convert to Formatted Date String - 22 Feb 2021.lna