views:

59

answers:

2

hello,

pls i want to convert this 06-29-2010 04:00PM to this format Y-m-d h:i:s in php

thanks

+2  A: 

Use strtotime:

$date  = '06-29-2010 04:00PM';
$date  = str_replace('-', '/', $date);
echo date('Y-m-d h:i:s', strtotime($date));

Result:

2010-06-29 04:00:00
Sarfraz
+1 I saw that :)
Babiker
Errorconverting this 06-21-2010 05:00PM gives me this 1970-01-01 01:00:00.any ideas
Smith
@Smith: See my updated answer please, that was because of `-` in the date.
Sarfraz
thanks for your help
Smith
@Smith: You are welcome :)
Sarfraz
You guys are so fast. In less that 30mins I get many questions answered. why do you guys help so quickly, are you paid? am a developer too.Great job!
Smith
@Smith: It is great pleasure to help others all volunteer (no pay). Also we learn a lot here at this great site :)
Sarfraz
A: 

I'll go ahead and offer PHP's date() manual as a second resource.

Babiker