Convey a string to a date

-2

I want to convert '01102018' in '01 -10-2018 ' I tried with date, but I have not been successful, thank you in advance.

date'('d-m-y','01102018');'
    
asked by Ed Brennenburg 03.01.2019 в 20:29
source

1 answer

2

Dear.

To solve your problem try the following:

//crea la variable de tipo date desde la fecha de tipo texto del ejemplo
$date = DateTime::createFromFormat('dmY', "01102018");
//formatea la fecha para imprimirla con el formato deseado
$date = $date->format('d-m-Y');
//imprime la variable
echo $date;

With that should be enough.

    
answered by 03.01.2019 / 20:35
source