date difference in days in javascript? -


I know how to use javascript, but I do not have any profound knowledge about it. I know how to find a difference in PHP in February, but in this case, I need a Javascript solution. Honestly, I do not even know that it is possible to do this with JavaScript. I think this is, but it's just an estimate.

Here is the html I have:

   

These two fields are actually bootstrap date pickers, they always come with some default values. Now, I want the user to change those two values ​​to calculate the difference between two dates (Alerts or Console logs, I will find my way out there).

The problem is that I have no clue where it starts from and how to calculate it again, I think the changing event can be a good candidate but ... I do not know how the difference To calculate.

Any help would be appreciated.

Regards, John

You can make your string a javascript date first Like:

  var start = $ ("input [name = checkin]"). Val (). Split ("/"); Var end = $ ("input [name = checkout]"). Val (). Split ("/"); Var startDate = new date (start [2], start [1] -1, start [0]); Var Enddate = New Date (Termination [2], End [1] -1, End [0]);  

Then you can simply reduce dates from each other:

  end date - start date  

this subtract To change the difference of time in milliseconds , divide it by a number of milliseconds in one day ( 1000 * 60 * 60 * 24 ).

Now there is a difference in your days, for example, see.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -