Set DateTime formatting Null values to "Invalid DateTime" instead of Null value

Describe the problem/error/question

Previous nodes converting a date value from a format to the desired format (for later comparison and insertion to MySQL

image

image

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node


{

"ClosingDate": 
"Invalid DateTime",
"MS.FileStarted": 
"2023-09-05",
"MS.Submission": 
"Invalid DateTime",
"MS.Processing": 
"Invalid DateTime",
"MS.Resubmittal": 
"Invalid DateTime",
"MS.ClearToClose": 
"Invalid DateTime",
"MS.ConditionalApproval": 
"Invalid DateTime",
"MS.SuspenseDate": 
"Invalid DateTime",
"MS.WarehouseDate": 
"Invalid DateTime",
"MS.Ship2InvestorDate": 
"Invalid DateTime",

Ideally they’d be null values rather than “Invalid DateTime” since when inserted into the DB they turn into “0000-00-00” instead.

Information on your n8n setup

  • n8n version: 1.4.1
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu 22.04 LTS

Honestly I’ll take whatever fix is easier, a code node which substitutes all the values “Invalid DateTime” with “”

or

Something conditional in the formatting to replace a non-matching format with the null value.

Hi @bdinsmore, welcome to the community!

Based on your description I reckon you could handle this with the ternary operator. This would leave empty strings untouched.

Example workflow:

Result:

Hope this helps!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.