php - What's better: date() or DateTime::format()? -


i'm working in server environment php 5.3.

to create mysql datetime string representing current time, have used date("y-m-d h:i:s") in code. new datetime("now")->format("y-m-d h:i:s") can't parsed in version. however, i'm figuring if can rely in date() function this.

and in source files i'm using datetime::createfromformat('y-m-d h:i:s', $mysqldate)->format('d/m/y h:i') obtain more friendly date brazilian visitors.

the question: spaghetti code? can have more concise code?

datetime little more fast see here , have daylight timezone support, date() can fast code, because it's better use datetime oop logic

$st = microtime(); echo date('m/d/y h:i').' '.(microtime()-$st).'<br>'; $st = microtime(); $d = new datetime(); echo $d->format('d/m/y h:i').' '.(microtime()-$st); 

you can use datetime in procedural style

echo date_format(date_create($date),$format); 

Comments