I'm having a problem with date format, if I put dateFormat: 'dd/mm/yy
, my alert returns me invalid date, if I pull it off and leave American default then returns the date. Any ideas how to resolve this?
I want to keep the Brazilian standard date, but not only with a mask but the format itself.
Follow the example in JSFiddle
<div id="teste">
<label class="fa fa-calendar">
<input id="startDate" name="start_at" placeholder=" " class="data-charts" type="text" value="">
</label>
<label class="fa fa-calendar">
<input id="endDate" name="end_at" placeholder=" " class="data-charts" type="text" value="">
</label>
<button type="button" class="btn btn-apply">Aplicar</button>
</div>
$(document).ready(function() {
$("#startDate").datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
$("#endDate").datepicker("option","minDate", selected)
}
}).datepicker("setDate", "-7", new Date());
$("#endDate").datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
$("#startDate").datepicker("option","maxDate", selected)
}
}).datepicker("setDate", new Date());
function dateInterval() {
var data_inicial = document.getElementById("startDate").value;
var data_final = document.getElementById("endDate").value;
var date1 = new Date(data_inicial);
var date2 = new Date(data_final);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if(diffDays <= 30)
{
alert(date1);
}else
{
alert(date1);
}
};
$(".btn-apply").on('click',function(){
dateInterval();
});
});