'error', 'message' => 'No se recibieron datos', ]); exit; } /* { "IdNivel": 1, "IdPeriodo": 635, "NombreNivel": "LICENCIATURA", "NombrePeriodo": "241", "in_db": false inicio, fin } */ // insert into database setlocale(LC_TIME, 'es_MX.UTF-8'); $formatter = new IntlDateFormatter('es_MX', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Mexico_City', IntlDateFormatter::GREGORIAN, 'MMMM'); $inicio = strtotime($data['inicio']); $fin = strtotime($data['fin']); try { $result = $db->insert('periodo', [ 'id_periodo_sgu' => $data['IdPeriodo'], 'periodo_nombre' => "{$data['NombreNivel']}: {$formatter->format($inicio)} - {$formatter->format($fin)} " . date('Y', $inicio), 'nivel_id' => $data['IdNivel'], 'periodo_fecha_inicio' => $data['inicio'], 'periodo_fecha_fin' => $data['fin'], 'estado_id' => 4, 'periodo_clave' => $data['NombrePeriodo'] ], ['id_periodo_sgu']); } catch (PDOException $th) { echo json_encode([ 'success' => false, 'message' => $th->getMessage() ]); exit; } echo json_encode($result ? [ 'success' => true, 'message' => 'Periodo agregado correctamente' ] : [ 'success' => false, 'message' => 'Error al agregar el periodo' ]);