Nicole

Calculate Dates

Discussion created by Nicole on Feb 28, 2019
Latest reply on Mar 14, 2019 by ChristofN

Hello,

 

I want to calcalute a date and I have some problem with it.

 

Example 1:

I have a field of the Type Date

I want to work with this date for example calculate + 1 Year or give it a new format like dd.mm.yyyy

 

but it don't work with this.

var date = new Date();
var newdate = new Date([[Start_x0020_date]]);
newdate.setDate(newdate.getDate());
var dd = newdate.getDate();
var mm = newdate.getMonth() +1;
var y = newdate.getFullYear();

var someFormattedDate = y + '/' + '0'+mm + '/' + dd;

return someFormattedDate;

 

What is wrong?

 

Example 2:

 

I have a form with a date field "Created" (=[[Erstelldatum]]). In the list settings I have set that per default the value should be today.

I have a seconde date field "Expire Date". I want to calculate the Expire Date in Rich Forms --> Behaviour with a Function Code.

 

I have done it with this code.

var str = [[Erstelldatum]];
var array = str.split(".",3);
var date= array[2]+"-"+array[1]+"-"+array[0];

var newdate = new Date(date);
newdate.setDate(newdate.getDate()+730 );
var dd = newdate.getDate();
var mm = newdate.getMonth() + 1;
var y = newdate.getFullYear();
var FullDate = dd + '.' + mm + '.' + y;
return FullDate;

 

Why I have gone this way? [[Erstelldatum]] = 08.02.2019 and I get an error doing this

var newdate = new Date([[Erstelldatum]])

 

is there a much more easier way to do the calculation?

how can I easily format date fields in skybow?

 

Kind regards

Nicole 

Outcomes