Convert PHP data to save to Mysql database

Asked

Viewed 1,251 times

0

I need to receive a date using the datapicker as dd/mm/yyyy and switch to database format (mysql).

have the access methods (Getter and Setter) in them applied this date function and strstring to convert:

function setDatavenc($datavenc) {
    $this->datavenc = date('d/m/Y', strtotime($datavenc));
}

.

function getDatavenc() {
    return date('d/m/Y', strtotime($this->datavenc));
}

But when saving in the bank saved 0000-00-00 And when making the query returns: 01/01/1970.

I’ve searched a lot including some form here in stackoverflow and none worked.

  • Enter the code (SQL) of how you save the date

  • $sql = "INSERT INTO spent (datavenc, input date)" . " VALUES(:datavenc, :input date)";

  • you go from ta to format d/m/Y or Y-m-d?

  • Step via input type="text" using the datapicker as d/m/Y I need it to reach the bank in format Y-m-d and then do the recovery to display the input as`d/m/Y'

1 answer

1

The PHP date function works as follows:

string date ( string $format [, int $timestamp ] )

The format you can insert the way you need, using is TABLE , from the PHP documentation page. In your case how you need the format 0000-00-00 the code would look like this:

function setDatavenc($datavenc) {
    $this->datavenc = date('Y-m-d', strtotime($datavenc));
}
  • Still saving zero: 0000-00-00

  • @JB_ Checks how the value of your variable is getting $datavenc

  • When it contains value: "2018-09-05", entered manually into the bank, when reset to "-0001-11-30"

Browser other questions tagged

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