2010-12-27 7 views
13

私はdbに格納されている2つの日付を持っており、$ .ajax()を使って選択しています。必要なものは、dbから選択した日付の間にdatepickerの値を表示することです。 it.Butそれはjquery datepickerの日付範囲を2つの日付を指定して制限する方法はありますか?

function setDatePickerSettings(isFisc) { 
     var fSDate, fEDate; 
     $.ajax({ 
      type: "POST", 
      url: '../Asset/Handlers/AjaxGetData.ashx?fisc=1', 
      success: function(data) { 
       alert(data); 
       var res = data.split("--");//data will be 4/4/2010 12:00:00--5/4/2011 12:00:00 
       var sDate = res[0].split(getSeparator(res[0])); 
       alert("Separator " + getSeparator(res[1]) + " Starts " + sDate); 
       var eDate = res[1].split(getSeparator(res[1])); 
       alert("End " + eDate); 
       alert("sub " + sDate[0]); 
       fSDate = new Date(sDate[2].substring(0, 4), sDate[0], sDate[1]); 
       alert("Starts " + fSDate.substring(0, 4)); 
       fEDate = new Date(eDate[2].substring(0, 4), eDate[0], eDate[1]); 
       alert("eND " + fEDate.toString()); 

      } 

     }); 
      var dtSettings = { 
     changeMonth: true, 
     changeYear: true, 
     showOn: 'both', 
     buttonImage: clientURL + 'images/calendar.png', 
     buttonImageOnly: true, 
     showStatus: true, 
     showOtherMonths: false, 
     dateFormat: 'dd/mm/yy', 
     minDate:fSDate, //assigning startdate 
     maxDate:fEDate //assigning enddate 
    }; 

    return dtSettings; 
} 

Plsのは、いくつかのソリューションを提供し、適切に動作していないため

は、ここに私のコードです。私はその範囲の間の値を必要とするdatetimeピッカーが必要です。事前に感謝します

+0

+1便利な質問です。 – gotqn

答えて

38

minDate/maxDateの構文が間違っています。 You can read the documentation on the jQuery UI website where the demo is。私はあなたの事例に合わせてそれを見てみることをお勧めします。あなたが今日に以前のものを選ぶことができないように、次はそれを作るだろう

$(".selector").datepicker({ minDate: new Date(2007, 1 - 1, 1) }); 

または

:それは次のようになります。

$(".selector").datepicker({ minDate: 0 }); 

、あなたは明日の前に

$(".selector").datepicker({ maxDate: 1 }); 

編集何かを選ぶことができないので、これはそれを行います。ここでは、あなた自身の日付を挿入する方法ですが、私はDATEFORMATを取得し、問題を抱えているが私はdateFormatを指定しているが、私が実際に入れたフォーマットはdateformatを無視していることがわかります。

$("#txtDateStart").datepicker({dateFormat:'mm/dd/yy', minDate: new Date(2010,11,12) }); 
+0

then 2004-4-1としてminを、2008-2-12としてmaxを与える方法はありますか? – kbvishnu

+1

@ハリー、私は私の答えを更新しました。これは役に立ちますか? –

0

私はこの1つを使用して、私はこれが私のために働いoutput.thanksにすべて

function setFiscDatePickerSettings() { 

     var fSDate, fEDate, sDate, fEDate; 
     var dtSettings; 
     sDate = document.getElementById("<%=hdfFiscStart.ClientID %>").value.split(getSeparator(document.getElementById("<%=hdfFiscStart.ClientID %>").value)); 
     eDate = document.getElementById("<%=hdfFiscEnd.ClientID %>").value.split(getSeparator(document.getElementById("<%=hdfFiscEnd.ClientID %>").value)); 
     fSDate = new Date(sDate[2].substring(0, 4), sDate[0] - 1, sDate[1]); 
     fEDate = new Date(eDate[2].substring(0, 4), eDate[0] - 1, eDate[1]); 
     dtSettings = { 
      changeMonth: true, 
      changeYear: true, 
      showOn: 'both', 
      buttonImage: clientURL + 'images/calendar.png', 
      buttonImageOnly: true, 
      showStatus: true, 
      showOtherMonths: false, 
      dateFormat: 'dd/mm/yy', 
      minDate: fSDate, maxDate: fEDate 
     }; 

     return dtSettings; 
    } 


    function bindFiscalDatePicker() { 
     var inputDt = $("input.datepicker_fisc"); 
     inputDt.addClass("numbers_only"); 
     inputDt.addClass("allow_special"); 
     inputDt.attr("symbolcodes", "/"); 
     inputDt.datepicker(setFiscDatePickerSettings()); 
    } 
1

を得ました。

$('#date-time-picker').datepicker({ 
    format: 'YYYY-MM-DD', 
    useCurrent: false, 
    showClose: true, 
    minDate: '2018-02-01', 
    maxDate: '2018-03-15', 
}) 
関連する問題