誰かがここで何が問題になっているのかわかりますか?日付が計算されるphp変数からdatepickerの最大日付を設定しようとしています。
利用した:
$ac_start_date = 01-08-2012
$ac_start_date = 20120801
しかし、どちらも機能していません。
$(document).ready(dialogForms);
function dialogForms() {
$('a.menubutton').click(function() {
var a = $(this);
$.get(a.attr('href'),function(resp){
var dialog = $('<div>').attr('id','formDialog').html($(resp).find('form:first').parent('div').html());
$('body').append(dialog);
dialog.find(':submit').hide();
dialog.dialog({
title: a.attr('title') ? a.attr('title') : '',
modal: true,
buttons: {
'Save': function() {
submitFormWithAjax($(this).find('form'));
location.reload();
$(this).dialog('close');
},
'Cancel': function() {$(this).dialog('close');}
},
close: function() {$(this).remove();},
width: 600,
height: 500,
show: "fade",
hide: "fade"
});
// do initialization here
$("#startdate").datepicker({
dateFormat: 'dd-mm-yy',
minDate: 'tomorrow',
maxDate: new Date("<?php echo $ac_end_date; ?>")
});
// do initialization here
$("#enddate").datepicker({
dateFormat: 'dd-mm-yy',
minDate: 'tomorrow',
maxDate: new Date("<?php echo $ac_end_date; ?>")
});
}, 'html');
return false;
});
}
回答の修正版を編集する
var ac_end_date = '07-31-2012'; // you want this to start out as a string
var ac_end_parsed = Date.parse(ac_end_date); // parse into milliseconds
var today = new Date().getTime(); // baseline
console.log(ac_end_date);
console.log(ac_end_parsed);
console.log(today);
var aDayinMS = 1000 * 60 * 60 * 24;
console.log(aDayinMS);
// Calculate the difference in milliseconds
var difference_ms = Math.abs(today - ac_end_parsed);
console.log(difference_ms);
// Convert back to days and return
var DAY_DIFFERENCE = Math.round(difference_ms/aDayinMS);
console.log(DAY_DIFFERENCE);
// do initialization here
$("#startdate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '0:+100',
minDate: '+1d',
maxDate: '+' + DAY_DIFFERENCE + 'd'
});
// do initialization here
$("#enddate").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '0:+100',
minDate: '+1d',
maxDate: '+' + DAY_DIFFERENCE + 'd'
});