Receive date and time without tabs and convert to date format

2

I would like to have the date and time in php, like this:

Example:

I would like to receive this date as follows:

09092017104430

And I would like the output to look something like this:

09/09/2017 10:44:30

    
asked by anonymous 09.09.2017 / 16:43

1 answer

3

Use the DateTime::createFromFormat method. You must pass in the first parameter the date input format. In the second parameter, you should put the string containing the value that will be interpreted as a date.

See:

$data = DateTime::createFromFormat('dmYHis', '09092017104430');


var_dump($data->format('d/m/Y H:i:s'));

The above style was written using OOP. But if you prefer, you can also use the functions below to do this:

$data = date_create_from_format('dmYHis', '09092017104430');


var_dump(date_format($data, 'd/m/Y H:i:s'));

Explanation of each value used in the format:

  

d = > day with two digits

     

m = > month with two digits

     

Y = > 4-digit year

     

H = > Current time, from 0 to 23, with two digits

     

i = > minute with two digits

     

s = > second with double digits

    
09.09.2017 / 17:01