How to decrease this code in PHP?

2

I am making a PHP code that formats the time the site looks for in the database. It's very simple. I wanted to know if you can reduce it. Here is the code:

$tempo = new DateTime($abre);
$abre = $tempo -> format('H:i');
$tempo = new DateTime($fecha);
$fecha = $tempo -> format('H:i');
    
asked by anonymous 03.05.2018 / 14:56

1 answer

8

You can do so by adding parentheses when creating the object you can already call some method of the class.

$abre = (new DateTime($abre))->format('H:i');
$fecha = (new DateTime($fecha))->format('H:i');
    
03.05.2018 / 14:59