How to add days to specific date?

Hi, I am trying to figure out (with ChatGPT) how add a number of days (I have this number in number field) to a specific date.

I have code like this:

const triggerDate = new Date(sequence_field_focus_date_start_date);
const daysToAdd = collected_touch_template_field_days_decimal_value;

const result = new Date(triggerDate);
result.setDate(result.getDate(sequence_field_focus_date_start_date) + daysToAdd);

console.log(result);

but my date field is empty. Not sure what I am doing wrong.

Maybe there is a website (like this one for PWA: https://workflow-automation.podio.com/help/php-calculation-examples.php) where I will find easy codes like this?

@Sandra here are Tape cheat sheet for calculation and also here.
I assume you have date field in your app, so I would use date field and add calculation for trigger date:

date_fns.addDays( [@Date with time ], 3)
2 Likes

base on this new date, so
date + days = new date
I want to trigger other flows, so not sure if I can do it based on calculation for a new date… ?

It is hard without seeing your workflow but in that case if you want to trigger other flows based on date I would use When a date field arrives trigger and than call other flows


. Hope this helps.

3 Likes

@Sandra as @tomaz says you can just add days but as I am not sure his example quite matches yours I thought I would add my 2 pence worth:

You can just take the collected_touch_template_field_days_decimal_value and add it to your sequence_field_focus_date_start_date within the create record you can call the collected value with the β€˜@’ no need for the script.

however, as regards your script it does look to me like there is a small mistake anyway:

melotte.consulting 2023-12-06 at 18.15.50

console.log(collected_sandra_core_field_focus_date_start_date)
console.log(collected_sandra_template_field_touch_days_decimal_value)
const d = date_fns.addDays(new Date(collected_sandra_core_field_focus_date_start_date), collected_sandra_template_field_touch_days_decimal_value);
console.log(d)
var_trigger_date = d

I believe the important bit that your script is missing though is:
var_trigger_date = result

Hope that helps

Jason

4 Likes