This topic is locked
[SOLVED]

 Calculate number of day automatically when two dates are selected

2/10/2014 8:52:24 AM
PHPRunner General questions
U
U.M.Mbanaso author

hello

all i want to do is to calculate the number of days between two dates when they are selected using date picker, my issue is that i don't know how to get the date in date format and use it to calculate the number of days between the two dates

i know how to get the value of using Runner.getControl(). now if i may ask is there any function in phprunner that is used to get the value into date format or should i just used the value i got to calculate the number of days? thanks in advance

Sergey Kornilov admin 2/11/2014

Here is the sample code that calculates difference in days between two date controls.
This code needs to be added to Javascript OnLoad event and field names need to be updated accordingly.

var ctrlDateListed = Runner.getControl(pageid, 'Date Listed');

ctrlDateListed.on('change', function(e){
var ctrlDateSold = Runner.getControl(pageid, 'Date Sold');

var d1 = new Date(this.getValue());

var d2 = new Date(ctrlDateSold.getValue());

var millisecondsPerDay = 1000 * 60 * 60 * 24;

var millisBetween = d1.getTime() - d2.getTime();

var days = millisBetween / millisecondsPerDay;

alert(days);
});
U
U.M.Mbanaso author 2/12/2014



Here is the sample code that calculates difference in days between two date controls.
This code needs to be added to Javascript OnLoad event and field names need to be updated accordingly.

var ctrlDateListed = Runner.getControl(pageid, 'Date Listed');

ctrlDateListed.on('change', function(e){
var ctrlDateSold = Runner.getControl(pageid, 'Date Sold');

var d1 = new Date(this.getValue());

var d2 = new Date(ctrlDateSold.getValue());

var millisecondsPerDay = 1000 * 60 * 60 * 24;

var millisBetween = d1.getTime() - d2.getTime();

var days = millisBetween / millisecondsPerDay;

alert(days);
});




Thanks Sergey it has solve my problem