Convert the date format the user types

2
Hello, I have the following code to format the date that the user informs and inserts in my bank:

$arrayData['data_validade'] = date_format("Y-m-d",strtotime(str_replace('/','-',$this->$arrayData)));

But, this date_format works only for the current date, but I do not want the current date, I want the date the user informs through my datapicker.

Any suggestions?

    
asked by anonymous 31.03.2015 / 15:30

3 answers

1

In this way I was able to solve:

$arrayData['data_validade'] = implode("-", array_reverse(explode("/", $arrayData['data_validade'])));
    
31.03.2015 / 15:38
0

I think the best way to revolve situations of the type, is with the object Datetime . It's always good to look at using the new PHP features.

$data = '17/07/2014';
$data_en = DateTime::createFromFormat('d/m/Y', $data);
print_r($data_en->format('Y-m-d')); //2014-07-17
    
08.09.2015 / 18:19
0

If you are using postgres, you can format the date at any time up to an insert, unlike mysql.

Before the main query this line will convert all fields from YYYY-MM-DD to DD/MM/YYYY all at once.

SET DATESTYLE TO SQL, DMY;
INSERT INTO tabela(data) VALUES('31/12/2015');
    
08.09.2015 / 19:12