How to convert a string into a date with PHP

0

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.

    
asked by Javier Rodríguez 27.03.2018 в 13:41
source

3 answers

1

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.

    
answered by 27.03.2018 в 14:40
0

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 .

    
answered by 27.03.2018 в 21:39
0

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()

    
answered by 29.03.2018 в 20:47