Fix UDF date formatting

Fixes #1046
I did not consider the deleted UDF case. That is valid, so maybe we should set ``datatype`` to 'unknown' or something similar if ``udf_def`` is none.