在表单上使用jquery日期选择器将用户输入转换为整数日期

时间:2017-08-07 10:33:22

标签: jquery mysql date datepicker

用户使用jquery日期选择器输入日期,这以mm / dd / yyyy格式显示,该表单用于使用以整数格式记录日期的列(CADNO)查询MySQL数据库,例如。 -3987。

-3987是从05/09/2006(这是日期kepreported_date列)计算出来的,这是因为CADNO列计算了今天date_date列的天数。

问题是,有没有办法在jquery上创建一个公式,将用户输入的日期转换为MySQL服务器期望的格式?

<script>

$(function(){

var dateFormat = "mm/dd/yy",

  date_from = $( "#date_from" )
    .datepicker({dateFormat: 'dd/mm/yy',
      defaultDate: "+1w",
      changeMonth: true,
        changeYear: true,
      numberOfMonths: 3
    })
    .on( "change", function() {

      date_to.datepicker( "option", "minDate", getDate( this ) );

    }),

  date_to = $( "#date_to" ).datepicker({dateFormat: 'dd/mm/yy',
    defaultDate: "+1w",
    changeMonth: true,
    changeYear: true,
    numberOfMonths: 3
  })
  .on( "change", function() {

    date_from.datepicker( "option", "maxDate", getDate( this ) );
  });
function getDate( element ) {
  var date;
  try {
    date = $.datepicker.parseDate( dateFormat, element.value );
  } catch( error ) {
    date = null;
  }
  return date;
}

});

ts=ts&"<form method='post' action='search_prep.asp'>"
ts=ts&"<tr><td>Search</td>"
ts=ts&"<td><select size='1' name='search_field' id='search_field'>"
for p=0 to colrows
	ts=ts&"<option value='"&cols(0,p)&"'>"&cols(1,p)&"</option>"
next
ts=ts&"</select></td></tr>"
ts=ts&"<tr><td>For</td>"
ts=ts&"<td><input type='text' size='12'  name='search_text' id='search_text' >"
ts=ts&"&nbsp;&nbsp;<input type='radio' name='andor' value='and'>AND"
ts=ts&" <input type='radio' name='andor' value='or' "&chkandor&">OR"
ts=ts&"&nbsp;&nbsp;<input type='text' size='12' name='search_text2' id='search_text2'></td>"
ts=ts&"<td><input type='checkbox' name='search2' value='yes' "&chk2stage&"  >2 Stage query required</td>"
ts=ts&"<td>"
ts=ts&"<input type='radio' name='repclr' value='radno' "&chkreprep&">Reports"
ts=ts&" <input type='radio' name='repclr' value='cadno' "&chkrepclr&" >Clears "
'ts=ts&" range between <select size='1' name ='date_from' id='date_from'>" -commented for datepicker
ts=ts&"</tr> "
ts=ts&"</td>"
ts=ts& "<tr><td>Date Between</td> <td><input type='text' style='text-align:center;' size='19' name='date_from' id='date_from'>"
'for i = mindate to maxdate-commented for datepicker
	'ts=ts&"<option value="&i&">"&date() + i&"</option>"-commented for datepicker
'next-commented for datepicker
'ts=ts&"</select>"-commented for datepicker

'ts=ts&"and<select size='1' name ='date_to' id='date_to'>"
'for i = maxdate to mindate step -1
'	ts=ts&"<option value="&i&">"&date() + i&"</option>"
'next
'ts=ts&"</select>"
ts=ts& "&nbsp;&nbsp;And&nbsp;&nbsp;<input type='text' style='text-align:center;' size='19' name='date_to' id='date_to'>"
ts=ts&"</td>"
  
ts=ts&"<td>&nbsp;&nbsp;<input type='submit' value='Go'></td>"


ts=ts&"</tr> "
ts=ts&"<input type='hidden' name='nocom' value='"&nocom&"'>"
ts=ts&"<input type='hidden' name='current_tech' value='"&current_tech&"'>"
ts=ts&"<input type='hidden' name='current_status' value='"&current_status&"'>"
ts=ts&"<input type='hidden' name='status' value='"&status&"'>"



ts=ts&"</form></table></div>"

1 个答案:

答案 0 :(得分:0)

使用以下代码段在javascript中创建一个函数:

CreateProcess

它将返回从给定的第一个日期到给定的第二个日期的天数。