Date conversion problem

Describe the problem/error/question

I try to combine a datetime from date in first strings and time in second one. I test the node without error but it return null in actual run. Am I doing anything wrong?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

{
“Store No_”:
“60”,
“Receipt No_”:
“601002976140”,
“Date”:
““2024-11-18T00:00:00.000Z””,
“Time”:
““1754-01-01T10:05:35.710Z””,
“Net Amount”:
34,
“DT”:
null
},

Information on your n8n setup

  • n8n version: 1.67.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: ubuntu 24

Hi @stevek

Thanks for posting here and welcome to the community! :cake:

I wasn’t able to reproduce this but perhaps I need your specific input data. Could you update your shared workflow with some pinned dummy data, so I can recreate this?

Tip for sharing your workflow in the forum

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

Make sure that you’ve removed any sensitive information from your workflow and include dummy data or pinned data as much as you can!


Also, your screenshot shows the JSON output. Is it the same in Table or Schema view?

Thanks for posting here and welcome to the community!

The issue seems to be related to how the Date and Time strings are formatted or whether they contain the expected data.

Try using an expression similar to this -

{{ (() => {
    const date = $json.Date || ''; // Fallback to empty string if null/undefined
    const time = $json.Time || ''; // Fallback to empty string if null/undefined
    
    // Check if date and time are long enough
    const formattedDate = date.length >= 11 ? date.substring(0, 11) : '';
    const formattedTime = time.length >= 23 ? time.substring(11, 23) : '';
    
    // Combine them with timezone offset
    return formattedDate + formattedTime + "+08:00";
})() }}

Could you also share the format in which the dates are being received?

1 Like

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