PHP | DateTime createFromFormat() Function

Syntax:
DateTime DateTime::createFromFormat( string $format, string $time, DateTimeZone $timezone )
example 1
<?php 
  
// Calling the DateTime:createFromFormat() function 
// with the format 'j-M-Y' and given DateTime is  
$datetime = DateTime::createFromFormat('j-M-Y', '30-September-2019'); 
  
// Getting the new formatted datetime  
echo $datetime->format('Y-m-d'); 2019-09-30
?> 
example 2
<?php 
  
// Calling the DateTime:createFromFormat() function 
// with the format 'j-M-Y' and given DateTime is  
$datetime = DateTime::createFromFormat('j-M-Y', '1-oct-2019'); 
  
// Getting the new formatted datetime  
echo $datetime->format('d-m-Y H:i:s'); 
?> 


No comments

Note: only a member of this blog may post a comment.