Can someone tell me how to convert a string
with a date in this format "2000-01-01 00:00:00"
to an object of type Date
?
I get the date from a query to a database mysql .
I know it must be silly, but I can not do it.
Can someone tell me how to convert a string
with a date in this format "2000-01-01 00:00:00"
to an object of type Date
?
I get the date from a query to a database mysql .
I know it must be silly, but I can not do it.
This example can help you.
<?php
$Fecha = "2018-03-27 08:15:00";
echo date("jS F, Y", strtotime( $Fecha)) . "<br>";
// salida 27th March, 2018
?>
Date formats In this link are the output formats that you can give.
Simple as:
$fecha = date("Y-m-d H:i:s", strtotime($aquilafechastring)), PDO::PARAM_STR);
On the PHP page you can check the Date format table .
To make format conversions I like to use the DateTime class ( link ).
Something like this:
$fecha = "2018-03-29 15:20:40";
$dt = new DateTime($fecha);
print $dt->format('d/m/Y'); // imprime 29/03/2018
print $dt->format('H:i:s'); // imprime 15:20:40
Accept the same formats as the function date()