Search code examples
phpdate-conversion

php date conversion to date having time


I am trying to convert php date conversion like 09/30/2011 to this format 2011-09-30 21:35:46.

I read some manuals but its going to be difficult for me.

$input = "09/30/2011";
$output = "2011-09-30 21:35:46";

$output = date('Y-m-d h:m:s', strtotime($input))

Solution

  • The format string 'Y-m-d h:m:s' should be modified to 'Y-m-d H:i:s' in your code. In date function, the format char 'm' is month, not minute; and 'h' is hour from 01 to 12, 'H' is hour from 00 to 23.