If I have a PHP string in the format of mm-dd-YYYY
(for example, 10-16-2003), how do I properly convert that to a Date
and then a DateTime
in the format of YYYY-mm-dd
? The only reason I ask for both Date
and DateTime
is because I need one in one spot, and the other in a different spot.
Alek RichterEnlightened
Use
strtotime()
on your first date thendate('Y-m-d')
to convert it back:Make note that there is a difference between using forward slash
/
and hyphen-
in thestrtotime()
function. To quote from php.net: