通过查看以下教程,我已经使用ajax实现了日期范围搜索:https://www.webslesson.info/2019/02/laravel-date-range-search-using-ajax-jquery.html
这很完美。我的问题是我的最后一个td输出正在显示带时间的日期。我想将此格式设置为仅显示“ m / d / Y”之类的日期。有人可以帮我吗?
我已经搜索并花费了数小时来执行此操作,但是很遗憾,我找不到任何有关执行此操作的线索。
$(document).ready(function(){
var date = new Date();
$('.input-daterange').datepicker({
todayBtn: 'linked',
format: 'yyyy-mm-dd',
autoclose: true
});
var _token = $('input[name="_token"]').val();
fetch_data();
function fetch_data(from_date = '', to_date = '')
{
$.ajax({
url:"{{ route('reports.fetch_data') }}",
method:"POST",
data:{from_date:from_date, to_date:to_date, _token:_token},
dataType:"json",
success:function(data)
{
var output = '';
$('#total_records').text(data.length);
for(var count = 0; count < data.length; count++)
{
output += '<tr>';
output += '<td>' + data[count].inventory_number + '</td>';
output += '<td>' + data[count].serial_number + '</td>';
output += '<td>' + data[count].title + '</td>';
output += '<td>' + data[count].price + '</td>';
output += '<td>' + data[count].created_at + '</td></tr>';
}
$('tbody').html(output);
}
})
}
$('#filter').click(function(){
var from_date = $('#from_date').val();
var to_date = $('#to_date').val();
if(from_date != '' && to_date != '')
{
fetch_data(from_date, to_date);
}
else
{
alert('Both Date is required');
}
});
$('#refresh').click(function(){
$('#from_date').val('');
$('#to_date').val('');
fetch_data();
});
});
function fetch_data(Request $request)
{
if($request->ajax())
{
if($request->from_date != '' && $request->to_date != '')
{
$data = DB::table('assets')
->whereBetween('created_at', array($request->from_date, $request->to_date))
->get();
}
else
{
$data = DB::table('assets')->orderBy('created_at', 'desc')->get();
}
echo json_encode($data);
}
}