Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/04/2013, 12:07
Avatar de catpaw
catpaw
 
Fecha de Ingreso: mayo-2010
Ubicación: xalapa
Mensajes: 856
Antigüedad: 14 años
Puntos: 23
Respuesta: fechas: sumar restar meses (datepicker)

hola leamsi23

Código Javascript:
Ver original
  1. $("#fecha_inicio").datepicker({
  2.     dateFormat: 'yy-mm',
  3.     showOn: "button",      
  4.     buttonImage: "../images_icon/datebox_arrow.png",
  5.     buttonImageOnly: true,
  6.     numberOfMonths: 2,
  7.     onSelect: function(selectedDate){
  8.         var fecha_fin = selectedDate; //sumar 1 mes a la fecha seleccionada
  9.         $("#fecha_final").datepicker("option", "minDate", selectedDate);//bloquear que no esconjan en la fecha final una fecha antes de la del inicio
  10.         $("#fecha_final").datepicker("setDate", fecha_fin); //aqui deberia ir la fecha +1 mes
  11.     }
  12. });
  13. $("#fecha_final").datepicker({
  14.     dateFormat: 'yy-mm',
  15.     showOn: "button",      
  16.     buttonImage: "../images_icon/datebox_arrow.png",
  17.     buttonImageOnly: true,
  18.     numberOfMonths: 2,
  19.     onSelect: function(selectedDate){
  20.         var fecha_inicio = selectedDate; //restar 1 mes a la fecha seleccionada
  21.         $("#fecha_final").datepicker("option", "maxDate", selectedDate); //bloquear que no esconjan en la fecha inicio una fecha despues del final
  22.         $("#fecha_final").datepicker("setDate", fecha_inicio);//aqui deberia ir la fecha -1 mes
  23.     }
  24. });

Pobre dejando el dateformat: yy-mm

y obtuve:

fecha_inicio [2013-04]
fecha_fin [2018-10]

cuando en fecha fin deberia ser [2013-04]

ya que:

var fecha_fin = selectedDate;

por el momento fecha_fin es igual ala fecha seleccionada, porque aun no le hayo como sumarle/restarle 1 mes

y si el dateformat es yy-mm-dd funciona

gracias