Server does not recognize function date_create_from_format

0

I am using the date_create_from_format function for dates

<?php 
$tiempo_pregunta = date_create_from_format('Y-m-d H:i:s', $pregunta->fecha." ".$pregunta->hora);
 ?>

But the problem is that the apache does not recognize that php function, check the configuration and that the library to use that function is installed, also check that the library is compatible with the version of php that has installed the server and yes it is.

Why is this happening?

    
asked by 20.03.2018 в 19:04
source

2 answers

1

I found the solution, just add this code and it was how everything was solved

<?php
date_default_timezone_set('America/Mexico_City');
?>
    
answered by 20.03.2018 в 19:13
0

You can do this in two ways:

Object Oriented:

<?php 
$tiempo_pregunta = DateTime::createFromFormat('j-M-Y H:i:s','15-Feb-2009 22:10:45');
echo $tiempo_pregunta ->format('Y-m-d H:i:s');
?>

By procedures:

<?php
$tiempo_pregunta = date_create_from_format('j-M-Y H:i:s','15-Feb-2009 22:10:45');
echo date_format($tiempo_pregunta , 'Y-m-d H:i:s');
?>
    
answered by 20.03.2018 в 19:15