Andrew Clark
Posts: 0
Joined: Sun Jan 05, 2014 1:26 pm

Calcuate days between 2 dates.

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Calcuate days between 2 dates.

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

Andrew Clark
Posts: 0
Joined: Sun Jan 05, 2014 1:26 pm

Calcuate days between 2 dates.

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

Jeffry Reed
Posts: 0
Joined: Sun Aug 14, 2016 3:59 pm

Calcuate days between 2 dates.

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

Andrew Clark
Posts: 0
Joined: Sun Jan 05, 2014 1:26 pm

Calcuate days between 2 dates.

thanks jeffry

Return to “Issues”