Page 1 of 1

Calcuate days between 2 dates.

Posted: Sun Dec 11, 2016 12:48 pm
by Andrew Clark

Hi

I am able to get a start and finish date from date picker and put them in two seperate labels. However I am unsure how to calculate the number of days between them. Reading through community comments I can see a range of comments about this and there appears to be a range of responses.

However I am unable to determine which is the preffered or best method.

I really seeking direction to basic script which could do this and simply display days between two dates.

Thanks in advance

Andrew


Calcuate days between 2 dates.

Posted: Sun Dec 11, 2016 1:13 pm
by Serhii Kulibaba

Hello Andrew,

Please use JS below for that:
prevar from = new Date($("[name=from] input").val());
var to = new Date($("[name=to] input").val());
var daysBetween = parseInt((from.getTime() - to.getTime())/86400000);/pre

here "from" and "to" - names of datepickers


Calcuate days between 2 dates.

Posted: Mon Dec 12, 2016 12:04 pm
by Andrew Clark

Sergiy

Thanks for this your rapid response - I seem not to be able to get it to work (more my lack of knowledge). To make it easier, I renamed datepicker1 "from" and datepicker2 "to". I also called the label where results were to be displayed "daysBetween".

I did not adjust the script at all -

var from = new Date($("[name=from] input").val());
var to = new Date($("[name=to] input").val());
var daysBetween = parseInt((from.getTime() - to.getTime())/86400000);

Was I suppoused to adjust the script at all ??

Thanks

Andrew


Calcuate days between 2 dates.

Posted: Mon Dec 12, 2016 2:39 pm
by Jeffry Reed

moment is a system library and has built in parsing and manipulation http://momentjs.com/docs/


Calcuate days between 2 dates.

Posted: Thu Dec 15, 2016 4:56 am
by Andrew Clark

thanks jeffry