I have an array called eventDates
, to which I want to add dates of type Date
. The dates I take from a call to a database, but I do not know how to include them in the array in Dates type.
This is the script:
var eventDates = {};
$.ajax({
dataType: 'json',
method: 'GET',
url: 'controller/reservas/reservasControllerMostrarFechasReservas.php',
success: function (res) {
eventDates= res;
}
});
This is the PHP part:
$consulta = 'SELECT fecha_reserva FROM reservas';
$fecha = parent::query($consulta);
$arrayFechas = array();
while ($fechas = mysqli_fetch_array($fecha)){
$arrayFechas[] = date('m/d/Y', strtotime($fechas['fecha_reserva']));
}
$verificar_fechas = parent::verificarRegistros($consulta);
for($i=0; $i<$verificar_fechas; $i++){
echo $arrayFechas[$i];
}
What I want is that in the end it is as if I did this but with the dates that I take the AJAX:
var eventDates = {};
eventDates[ new Date( '08/07/2018' )] = new Date( '08/07/2018' );
eventDates[ new Date( '08/12/2018' )] = new Date( '08/12/2018' );
eventDates[ new Date( '08/18/2018' )] = new Date( '08/18/2018' );
eventDates[ new Date( '08/23/2018' )] = new Date( '08/23/2018' );