Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/02/2013, 09:39
clebersonweng
 
Fecha de Ingreso: febrero-2013
Ubicación: Encarnacion
Mensajes: 7
Antigüedad: 11 años, 2 meses
Puntos: 0
Para los que necesiten calcular la cantidad de dias entre dos fechas por jquery

Este ejemplo calcula la cantidad de dias entre dos fechas con jquery e introducir en un input ai esta el codigo

<script>
var from = new Date();
var to = new Date();
var dayDiff = 1;
$(function() {
var dates = $("#from, #to")
.datepicker(
{
showOn : "button",
buttonImage : "images/calendar.gif",
buttonImageOnly : true,
alt:"calendario",
defaultDate : "+1w",
changeMonth : true,
numberOfMonths : 1,
minDate : -0,
onSelect : function(selectedDate) {
var option = this.id == "from" ? "minDate"
: "maxDate", instance = $(this).data(
"datepicker"), date = $.datepicker
.parseDate(
instance.settings.dateFormat
|| $.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option,
date);

if (this.id == "from") {
from = $(this).datepicker('getDate');
if (!(to == "")) {
update_days()
}
}
if (this.id == "to") {
to = $(this).datepicker('getDate');
update_days()
}
}
});
});

function update_days() {
dayDiff = Math.ceil((to - from) / (1000 * 60 * 60 * 24));
$("#days").empty()
$("#days").append(dayDiff)
$('#days').val(dayDiff)
}
</script>

y en el input se le le pone asi

<input type="text" id="days" name="days"
placeholder="Cantidad de dias" class="input-small"
value="">
se le toma el valor por el id.. ah no se debe olvidar las librerias de jquery.. :)