-2

I would like to convert 30.10.2014 15\:25\:24 to 30/Oct/2014 15:25:24. I tried it like this...

$s = '30.10.2014 15\:25\:24';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);

... but my result is 01.Jan.1970 01:00:00

peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

0

Its because strtotime returned FALSE , code shown below

$s = '30.10.2014 15\:25\:24';  //invalid format
$date = strtotime($s);
if($date===FALSE)  //if strtotime failed
{
    echo "strtotime failed";
}
Unni Babu
  • 1,839
  • 12
  • 16
  • Thank you, but how can I convert `30.10.2014 15\:25\:24` to `30/Oct/2014 15:25:24`? – peace_love Aug 28 '15 at 13:18
  • $s = str_replace("\\","/","30.10.2014 15\:25\:24"); – Unni Babu Aug 28 '15 at 13:20
  • dont forget to check this answer as accepted if ur satisfied :) – Unni Babu Aug 28 '15 at 13:20
  • Thank you, I tried `$s = str_replace("\\","/","30.10.2014 15\:25\:24")` as you said, but I still get the result `strtotime failed` – peace_love Aug 28 '15 at 13:24
  • if you remove / and \ this from time, you will get correct result.... try this ---> $s = '30.10.2014 15:25:24'; $date = strtotime($s); echo date('d/M/Y H:i:s', $date); – Unni Babu Aug 28 '15 at 13:25
  • I finaly found the problem. I need to write `$s = str_replace("\\","","30.10.2014 15\:25\:24");` and not `$s = str_replace("\\","/","30.10.2014 15\:25\:24");` – peace_love Aug 28 '15 at 14:49