Dates driving datepicker

0

I'm doing an employee control system, my problem is with the dates since I do not keep them as I should, this code is the one I use to collect the data within a form

<?php
//conectar a la base de datos 
include "conexion.php";
//realizar consulta 
$user_id=null;
$sql1= "select * from nomina where id= ".$_GET["id"];
$query = $con->query($sql1);
$person = null;
if($query->num_rows>0){
while ($r=$query->fetch_object()){
  $person=$r;
  break;
}

  }
?>

  <?php if($person!=null):?>

  <form role="form" method="post" action="php/actualizar.php"> //formulario para agregar o actualizar
    <div class="form-group">
      <label for="folionomina">Folio Nomina</label>
      <input type="text" class="form-control" value="<?php echo $person->folionomina; ?>" name="folionomina" id="folionomina">
      <label for="nombre_emp">Nombre de Empleado</label>
      <input type="text" class="form-control" value="<?php echo $person->nombre_emp; ?>" name="nombre_emp" id="nombre_emp">
      <label for="sueldodiario">Sueldo Diario</label>
      <input type="text" class="form-control" value="<?php echo $person->sueldodiario; ?>" name="sueldodiario" id="sueldodiario">
      <label for="sueldosemana">Sueldo Semanal</label>
      <input type="text" class="form-control" value="<?php echo $person->sueldosemana; ?>" name="sueldosemana" id="sueldosemana">
      <label for="descinfonavit">Descuento Infonavit</label>
      <input type="text" class="form-control" value="<?php echo $person->descinfonavit; ?>" name="descinfonavit" id="descinfonavit">
      <label for="descfonacot">Descuento Fonacot</label>
      <input type="text" class="form-control" value="<?php echo $person->descfonacot; ?>" name="descfonacot" id="descfonacot">
      <label for="puesto_emp">Puesto Empleado</label>
      <input type="text" class="form-control" value="<?php echo $person->puesto_emp; ?>" name="puesto_emp" id="puesto_emp">
      <label for="fechalta">Fecha de Alta</label>
      <input type="date" class="form-control" value="<?php echo $person->fechalta; ?>" name="fechalta" id="fechalta">
      <label for="fechamodsal">Fecha de Modificacion de salario</label>
      <input type="date" class="form-control" value="<?php echo $person->fechamodsal; ?>" name="fechamodsal" id="fechamodsal">
      <label for="fechabaja">Fecha de Baja</label>
      <input type="date" class="form-control" value="<?php echo $person->fechabaja; ?>" name="fechabaja" id="fechabaja">
      <label for="sueldocontrato">Sueldo Contrato</label>
      <input type="text" class="form-control" value="<?php echo $person->sueldocontrato; ?>" name="sueldocontrato" id="sueldocontrato">
      <label for="fechaini">Fecha de Inicio</label>
      <input type="date" class="form-control" value="<?php echo $person->fechaini; ?>" name="fechaini" id="fechaini">
      <label for="totaldias">Total de Dias</label>
      <input type="text" class="form-control" value="<?php echo $person->totaldias; ?>" name="totaldias" id="totaldias">

      <label for="fechaini">Fecha de Inicio</label> //aqui es donde tengo la duda al mandar el dato de fecha no lo recibe correctamente
      <input type="date" class="form-control" value="<?php echo $person->fechaini; ?>" name="fechaini" id="fechaini">



    </div>

    <input type="hidden" name="id" value="<?php echo $person->id; ?>">
    <button type="submit" class="btn btn-default">Actualizar</button>
  </form>
  <?php else:?>
  <p class="alert alert-danger">404 No se encuentra</p>
  <?php endif;?>

Now my doubt comes with the next part that is to save the date within the tables my question is the following, if I put a function to convert the received date into an array and that fix to convert it to a new variable must go before or in which part of the following code.

<?php
//aqui tengo duda de si poner una funcion que reciba la fecha y la cambie mediante un arreglo pero si seria antes o despues 




if(!empty($_POST)){
    if(isset($_POST["puesto"]) &&isset($_POST[$fechacambiada])){
        if($_POST["puesto"]!=""&& ){
            include "conexion.php";

            $sql = "insert into puestos(puesto,creadoel) value (\"$_POST[puesto]\",NOW())";
            $query = $con->query($sql);
            if($query!=null){
                print "<script>alert(\"Agregado exitosamente.\");window.location='../ver.php';</script>";
            }else{
                print "<script>alert(\"No se pudo agregar.\");window.location='../ver.php';</script>";

            }
        }
    }
}



?>

I appreciate any kind of help

    
asked by franksegovia 05.06.2018 в 16:34
source

1 answer

0

The simplest way is to format the date in the query itself in mysql , assuming that the field fechaini has an appropriate date format:

SELECT *, 
    DATE_FORMAT(fechaini, '%d/%m/%Y') AS fechaini_format FROM NOMINA WHERE id= ".$_GET["id"];

The other option is to modify the format in php before filling in the corresponding input:

<?php 
$fechaini_format = date("d/m/Y", strtotime($person->fechaini));
?>
    
answered by 05.06.2018 / 17:27
source