Q:

Write a PHP script to a convert string to Date and DateTime

0

Write a PHP script to a convert string to Date and DateTime.

Sample Date : '12-08-2004'
Note : PHP considers '/' to mean m/d/Y format and '-' to mean d-m-Y format

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
$dt = DateTime::createFromFormat('m-d-Y', '12-08-2004')->format('Y-m-d');
echo $dt;
?>

Sample Output:

2004-12-08

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now