Pregunta

H

Necesito personalizar dos datepickers.

En primer lugar shold tiene:

  • MinDate: últimos diez días de este mes (o si más fácil: 20 de este mes)
  • MaxDate: 10 de próximo mes

Sólo puede establecer a continuación, como se da en "manual" de esta manera: + 1m + 2w + 5d. Pero eso no es bueno en mi caso ya que no necesito ir relativa a los datos actuales.

¿Alguna idea?

He intentado esto sin suerte:

// temp vars used below
var currentTime = new Date()

// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
    dateFormat: 'dd.mm.yy',
    // minDate: '+10d',
    minDate: new Date(currentTime.getYear(), currentTime.getMonth(), 20),
    maxDate: '+3w'
});

BR. Anders

ACTUALIZACIÓN - Solución He utilizado la respuesta de undertakeror y funciona muy bien. Thnaks para la respuesta: -)

// temp vars used below
var currentTime = new Date();
var startDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -10); // 10 days before next month
var startDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, -1); // one day before next month
var endDateFrom = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 3); // 3rd of next month
var endDateTo = new Date(currentTime.getFullYear(), currentTime.getMonth() +1, 10); // 10th of next month

// DATEPICKER CURENT MONTH - all fields with class: datepicker_current_month
$(".datepicker_current_month").datepicker({
    dateFormat: 'dd.mm.yy',
    minDate: startDateFrom,
    maxDate: startDateTo
});
¿Fue útil?

Solución

Este es un plugin agradable y tiene una gran cantidad de opciones de configuración http://plugins.jquery.com/ proyecto / selector de fechas . Puede encontrar la documentación aquí http://www.kelvinluck.com /assets/jquery/datePicker/v2/demo/documentation.html y algunos demos aquí http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/

Dicho esto, no sé si es más fácil de usar que el que lo intentó, pero la idea es que usted todavía tiene que calcular los días a sí mismo, algo así como http://jsfiddle.net/m2HPr/2/

Espero que ayuda

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top