This topic is locked
[SOLVED]

 Difficult to adapt a code

3/17/2021 5:51:59 PM
PHPRunner General questions
brito author

I'm having difficulty adapting a code for my project, I need to add days to a date with javascript but the result is expected, could someone help me
follow the code below
var ctrlinicio = Runner.getControl(pageid, 'inicio');

var ctrln_dias = Runner.getControl(pageid, 'n_dias');

var ctrltermino = Runner.getControl(pageid, 'termino');
function func() {

ctrltermino.setValue(Number(ctrlinicio.getValue()) + Number(ctrln_dias.getValue()));

};
ctrlinicio.on('keyup', func);

ctrln_dias.on('keyup', func);

S
skbrasil 3/17/2021



I'm having difficulty adapting a code for my project, I need to add days to a date with javascript but the result is expected, could someone help me
follow the code below
var ctrlinicio = Runner.getControl(pageid, 'inicio');

var ctrln_dias = Runner.getControl(pageid, 'n_dias');

var ctrltermino = Runner.getControl(pageid, 'termino');
function func() {

ctrltermino.setValue(Number(ctrlinicio.getValue()) + Number(ctrln_dias.getValue()));

};
ctrlinicio.on('keyup', func);

ctrln_dias.on('keyup', func);

S
skbrasil 3/17/2021




brito author 3/17/2021





in sql i already solved it, but i need the result before saving the record, the code works but i don't finish the date, it passes a numeral string.

fhumanes 3/18/2021

Hello:
I codified this example that I think gives solution to your problem.



var date1 = Runner.getControl(pageid, 'datepicker');

var dias = Runner.getControl(pageid, 'dias');

var date2 = Runner.getControl(pageid, 'finalDate');
function func() {

date1_m = date1.getMomentValue()

date1_m = date1_m + (dias.getValue()* 24 * 60 * 60 * 1000);

d = new Date();

d.setTime(date1_m);

date2.setValue(d);

};
date1.on('keyup', func);

dias.on('keyup', func);


What it does is pass the initial date to UNIX date format (date in milliseconds) and adds the milliseconds corresponding to the days reported.
Then that data returns it to date format and assigns it to the field.
Greetings,

fernando.

brito author 3/19/2021



Hello:
I codified this example that I think gives solution to your problem.



var date1 = Runner.getControl(pageid, 'datepicker');

var dias = Runner.getControl(pageid, 'dias');

var date2 = Runner.getControl(pageid, 'finalDate');
function func() {

date1_m = date1.getMomentValue()

date1_m = date1_m + (dias.getValue()* 24 * 60 * 60 * 1000);

d = new Date();

d.setTime(date1_m);

date2.setValue(d);

};
date1.on('keyup', func);

dias.on('keyup', func);


What it does is pass the initial date to UNIX date format (date in milliseconds) and adds the milliseconds corresponding to the days reported.
Then that data returns it to date format and assigns it to the field.
Greetings,

fernando.


Thank you very much, it worked perfectly.