# Invalid DateTime in Set node with DateTime() function

**URL:** <https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653>\
**Category:** Questions\
**Tags:** expressions\
**Created:** [April 27, 2023, 12:31pm UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653 "2023-04-27T12:31:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eventurum](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/eventurum/32/24447_2.png) [@Eventurum](https://community.n8n.io/u/Eventurum)\
**Post date:** [April 27, 2023, 12:31pm UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653/1 "2023-04-27T12:31:48Z")

</div>

## Hello everyone. I need help.

I have 7 different dates in format MM/DD/YYYY. But I need another format DD.MM.YYYY. I want to change format in Set node because I don’t want my workflow to be bulky with 7 Date & Time nodes. But I get this issue:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/5/8/582d5669a463896dfa72c73a2b60ca75a9d85f93.png)

My Set node input:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/8/5/85f0d5203ea2655cbc30f8e946b18d768de0d918.png)

Also I have to delete expressions with date \< 01.01.1900. Maybe I can do both tasks with Code node, but Im pretty bad with JavaScript. Maybe You can help me?

## Information on your n8n setup

- **n8n version:** 0.224.4
- **Database:** SQLite
- **n8n EXECUTIONS\_PROCESS setting:** main
- **Running n8n via:** Docker Compose
- **Operating system:** Ubuntu

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [May 2, 2023, 11:44am UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653/3 "2023-05-02T11:44:53Z")

</div>

Hi @Eventurum, I am sorry you’re having trouble.

tl;dr: you probably want to use this expression

```auto
{{ DateTime.fromFormat($json["PM clinic"], 'L/d/yyyy').toFormat('d.LL.yyyy') }}

```

Full explanation:

In an n8n expression (and JavaScript in general), the single quotes `'` would indicate the beginning and end of a string. So in an expression like `DateTime.fromFormat('$json["PM clinic"]', 'L/d/yyyy').` n8n would try to parse a string of `$json["PM clinic"]` which fails.

If you don’t use the quotes, n8n would parse the **value** of your `PM clinic` field instead. Here’s an example workflow showing this:

This is the result:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/a/a/aa3f72af4d25bddb6d2a38a53bffe24692a2f0fb.png)

Hope this helps!

As for your second question, deleting dates before 1900, can you confirm what exactly you want to delete? Do you want to remove the entire item or just the specific value?

---

<div class="post-metadata">

**Author:** ![Eventurum](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/eventurum/32/24447_2.png) [@Eventurum](https://community.n8n.io/u/Eventurum)\
**Post date:** [May 2, 2023, 12:05pm UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653/4 "2023-05-02T12:05:44Z")

</div>

Hello @MutedJam, thank you for your reply.

Your answer about DateTime() helped me a lot.

As for the second question:  
I want to keep only Inspections which were made after 01.01.1900. So I want to remove values which \< 01.01.1990

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [May 2, 2023, 1:11pm UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653/5 "2023-05-02T13:11:01Z")

</div>

In this case I think the easiest approach would be to first parse the date, then use the IF node to check if it was before 1990. Here’s an example, filtering the `Bucket Inspection` field (you can of course change this and add more conditions for additional fields as needed):

You can see that only the item with a `Bucket Inspection` date after 1990 would pass the IF node here:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/7/8/7848282cfb80801660cad0eeda23326bc0e1b1bf.png)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Eventurum](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/eventurum/32/24447_2.png) [@Eventurum](https://community.n8n.io/u/Eventurum)\
**Post date:** [May 2, 2023, 2:28pm UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653/6 "2023-05-02T14:28:15Z")

</div>

Thank you so much!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [May 9, 2023, 2:28pm UTC](https://community.n8n.io/t/invalid-datetime-in-set-node-with-datetime-function/25653/7 "2023-05-09T14:28:20Z")

</div>

Closed on May 9, 2023, 2:28pm UTC

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