0

I'm trying to store the current date and time in a MySQL database, but when storing it stores in a different format:

  • I'm using date("Y-m-d H:i:s");

  • But it's stored as 20/16/1017

  • It should be 2016-10-17 15:23:23

View

$date = date("Y-m-d H:i:s");
<input type="hidden"  name="date" id="date" value="<?php echo $date; ?>">

Model

function InsertAdd($data)
    {
        $this->db->insert('advertisements', $data);
    }

Controller

$data = array(

                    'Date' => $this->input->post('date'),

                );

Note: - i have changed my type to datetime and default is currenttime in mysql db

colombo
  • 520
  • 2
  • 9
  • 24

1 Answers1

-2

use strtotime to replace slash with - signs. Below should work:

  $date = date('Y-m-d h:i:s', strtotime(str_replace('/', '-', $date)));
vaxzz
  • 88
  • 8