4
I needed to find a mechanism to limit a search no longer than 3 months.
I have two dates, I want to validate if they are within the defined parameters.
have this code() I am using type date and datepicker to run on various browsers
<script src="data/js/moment.js" type="text/javascript"></script>
<script type="text/javascript">
$("#pesquisa").on("submit", function (event) {
event.preventDefault();
var start= new Date(document.getElementById("datainicio").value);
var end = new Date(document.getElementById("datafim").value);
var dr = moment.range(start, end);
dr.diff('months'); // 3
dr.diff('days'); // 92
alert( dr.diff();) // 7945200000
// mostrarinfo();
});
Related: http://answall.com/q/13046/227
– utluiz
I’ve seen it, but it doesn’t work
– usersantos
To better help colleagues answer you, try to explain what you’ve tried. Provide sample codes of attempts you made and where or what isn’t working.
– Anderson Madeira
for now I have only this, I will fetch the fields var dateinicio= Document.getElementById("start date"); var datafim = Document.getElementById("end date"); var datestart= new Date(); var dateend= new Date();
– usersantos
To solve this in an elegant and quick way use the momentjs.
– Bruno Wego
See this library that has example of how to calculate the difference.
– Bruno Wego
thanks :) I will try to put here the solution
– usersantos
None of the answers offered will satisfy you?
– Jonatas Walker