This topic is locked

Add 1 Hours to time

12/17/2018 12:19:06 PM
PHPRunner General questions
G
georgweber author

I have a code which fill The Value in H1 to H2 on the fly. The value in H1 is "08:00" (Like time)
Code:

var ctrlH1 = Runner.getControl(pageid, 'H1');

var ctrlH2 = Runner.getControl(pageid, 'H2');

function func() {
ctrlH2.setValue(ctrlH1.getValue());

};

ctrlH1.on('change', func);
This work´s. But in need now to add 1 hour to the H1 and store it in H2. The result in H2 sould be "09:00"
Can everybody help me to do this?

W
WilliamBDevClub member 12/17/2018

You could use this:

ctrlH2.setValue(ctrlH1.getValue() + (1 * 60 * 60 * 1000));


It will add 1 hour in milliseconds.

G
georgweber author 12/17/2018



You could use this:

ctrlH2.setValue(ctrlH1.getValue() + (1 * 60 * 60 * 1000));


It will add 1 hour in milliseconds.


Thank you for answer, but does´t work

the code now look like this:
var ctrlH1 = Runner.getControl(pageid, 'H1');

var ctrlH2 = Runner.getControl(pageid, 'H2');

function func() {
ctrlH2.setValue(ctrlH1.getValue() + (1 60 60 * 1000));

};

ctrlH1.on('change', func);
maybee because the format from H1 is "08:00"

G
georgweber author 12/17/2018



Thank you for answer, but does´t work

the code now look like this:
var ctrlH1 = Runner.getControl(pageid, 'H1');

var ctrlH2 = Runner.getControl(pageid, 'H2');

function func() {
ctrlH2.setValue(ctrlH1.getValue() + (1 60 60 * 1000));

};

ctrlH1.on('change', func);
and de result is 08:003600000

W
WilliamBDevClub member 12/17/2018





Sorry my bad. Try this.



var ctrlH1 = Runner.getControl(pageid, 'H1');

var ctrlH2 = Runner.getControl(pageid, 'H2');

function func() {

var d = new Date(ctrlH1.getValue());

d.setHours(d.getHours() + 1);

var t = d.getTime();

ctrlH2.setValue(t);

};

ctrlH1.on('change', func);
G
georgweber author 12/20/2018



Sorry my bad. Try this.



var ctrlH1 = Runner.getControl(pageid, 'H1');

var ctrlH2 = Runner.getControl(pageid, 'H2');

function func() {

var d = new Date(ctrlH1.getValue());

d.setHours(d.getHours() + 1);

var t = d.getTime();

ctrlH2.setValue(t);

};

ctrlH1.on('change', func);



Sorry my friend. Do not work. The result is "NaN"

W
WilliamBDevClub member 12/20/2018



Sorry my friend. Do not work. The result is "NaN"


That is "Not A Number". I am just guessing ideas here as I do not use time or dates in a string format. Much easier to use date format for them. You could look at this https://stackoverflow.com/questions/5619202/converting-a-string-to-a-date-in-javascript. This may also help https://hackernoon.com/a-quick-handbook-for-dates-in-javascript-7b71d0ef8e53.

A
ayctech 12/27/2018

a solution could be add by sql, create a new column in your select, for example h3, add an hour to h3 and assign that value to h2.
var ctrlH3 = Runner.getControl (pageid, 'H3');
ctrlH2.setValue (ctrlh3.getValue ());