How to convert date into DateTime in php? 1


Date can be converted into DateTime using strtotime function.

strtotime() is used to convert a string value to DateTime. Check the following example to understand it in a better way:



Example 1:


$myDate = '03/06/2022';
$myDate = date('Y-m-d H:i:s',strtotime($myDate)); 
echo $myDate; 

 

 

Output:

2022-06-03 00:00:00

 

Example 2:

 

 

$myDate = '03/06/2022';
$myDate = date('d F,Y H:i:s',strtotime($myDate)); 
echo $myDate; 

 

Output:

3 June, 2022 00:00:00