Handling date and time in PHP

Asked

Viewed 382 times

0

I have a question. I would like to know how I can do so that the php code stores the time I registered an activity, but it should be hidden in the form and only visible when this data is visible in a table.

?>
<?php require "templates/header.php"; ?>

  <?php if (isset($_POST['submit']) && $statement) : ?>
    <blockquote> Registrado com sucesso! </blockquote>
  <?php endif; ?>

  <h2>Registrar Atividade</h2>

  <form method="post">
    <input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
    <label for="nome_atividade">Nome da Atividade: </label>
    <input type="text" name="nome_atividade" id="nome_atividade">
    <label for="duracao">Duração: </label>
    <input type="text" name="duracao" id="duracao">
    <label for="descricao">Descrição: </label>
    <textarea rows="4" cols="50" name="descricao" id="descricao"></textarea> <br>
    <input type="submit" name="submit" class="btn" value="Registrar">
  </form>
  
  <a href="registro_de_atividades.php">Voltar</a> <br>
  <a href="index.php">Voltar para o meu perfil</a> <br>

<?php require "templates/footer.php"; ?>

  • Nor need to be hidden in the form, just the server that receives this information save the time along with the form data. You can use the function date(). Example: date(""Y-m-d H:i:s"")

1 answer

0


Just that in your file registro_de_actividades.php, to which you send the form data, you create a variable that receives a date function, taking the current date and time. Follow example:

// aqui crio a variável $data e atribuo a função do php date(), passando a formatação de data desejada (no caso, no padrão de data do banco de dados)
$data = date('Y-m-d H:i:s');
// ... no seu SQL de registro passe a variável como valor do campo de data de registro

Follow the function documentation date: http://php.net/manual/en/function.date.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.