Pergunta

I have this string

$chktodate = "15/02/2014 9 am";

And when I am doing this

$timetocheck = strtotime($chkdt);

It gives me nothing.

Is it not that the function is supposed to take the string like the format which I mentioned ie 15/02/2014 9 am.

Foi útil?

Solução

strtotime() doesn't understand that format, and hence returns FALSE. The list of formats recognized by the parser are listed here.

Use DateTime::createFromFormat() to parse this format:

$dateObj = DateTime::createFromFormat('d/m/Y g a', $chktodate);
echo $dateObj->format('Y-m-d H:i:s'); // 2014-02-15 09:00:00

For a list of all the available formatting options, see the documentation.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top