Javascript to show date adjusted by number of days


I would like to ask for some help from this community please.

I have a complex date field (departure date) on one view, and then a list of 'trip day' records in a subsequent view that hold the details of each 'itinerary day' relating to that departure.

For example, if the departure date is on 22 Dec for a four day trip, then view 1 contains all the standard departure information, and view 2 contains a (variable length) list with 4 item records...Trip Day 1, Trip Day 2, Trip Day 3, Trip day 4)

What I would like to be able to do is display the calculated date for each trip adding the trip day number (1,2,3,4 etc) to the departure date...then displaying it in the view against each trip day (ie Trip Day 1 would show 22 Dec, Trip Day 2 would show 23 Dec etc)

Because these are standard 'Trip Days', I can't store this data against the record in the database, as it will only make sense in relation to a specific departure date.

What I would like to be able to do is:

1. Read a complex date value from a scene/field,

2. Add an integer to the start date (number of days, from a second scene list) to create a new date...

3. Insert a new line/field to show this date in each of the second list view entries

I have searched through the forums and haven't made much progress so far, so would appreciate any help please!

Many thanks,


I thought I would share my test attempt so far (excluding the date logic). I can access the fields I need, but I can't correctly insert the new line at the beginning of each item in the related-records 'list'. My code incorrectly inserts all lines before every list item.

Many thanks for any light you can shed!

$(document).on('knack-scene-render.scene_94', function(event, scene) {

/* find the return date */

var return_date = $(".field_49 .kn-value").text();

/* build the new line */

var data_view_219 = Knack.models['view_219'].data.toJSON();

for(x = 0; x < data_view_219.length; x++){

item = data_view_219[x];

var update_text = '<span>'+return_date+'+'+item.field_28_raw+' Test</span>';

$(update_text).insertBefore( ".field_28" );