Get weekday from previous node

In the workflow below I’m using a Java Script code to find the day of the week of a date.

It turns out that if I put the date in the code statically it works perfectly, if I search from the previous node it returns the date that comes from the previous node instead of returning the day of the week as it happens statically.

** This one below works wrong**

//Retorna o dia da semana entre 0 e 6
var day = new Date (‘data-buscada’).getDay();

//Array para atribuir o dia da semana junto a função .getDay()
const weekday = [“Domingo”, “Segunda-feira”, “Terça-feira”, “Quarta-feira”, “Quinta-feira”, “Sexta-feira”, “Sábado”];

//Atribui o nome do dia da semana à propriedade ‘day_today’
items[0].json.day_today = weekday[day];

return items;

Este abaixo retorna da forma que quero, mas, apenas de forma estática

//Retorna o dia da semana entre 0 e 6
var day = new Date (‘2023/03/08’).getDay();

//Array para atribuir o dia da semana junto a função .getDay()
const weekday = [“Domingo”, “Segunda-feira”, “Terça-feira”, “Quarta-feira”, “Quinta-feira”, “Sexta-feira”, “Sábado”];

//Atribui o nome do dia da semana à propriedade ‘day_today’
items[0].json.day_today = weekday[day];

return items;

Hi @admdiegolima, a line like var day = new Date('data-buscada').getDay(); would try to create a JS Date object based on the string “data-buscada”, not the value of your data-buscada field.

To reference data from previous nodes, you would need to use a suitable variable (or method) in your code node (such as $input.first().json["data-Buscada"]) in your example code like so:

This is the result:

Hope this helps! Let me know if you have any questions on this :slight_smile:

1 Like

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