tags:

views:

527

answers:

4

Hi there!

I have the following date: 2010-04-19 18:31:27. I would like to convert this date to the dd/mm/yyyy format.

Can anyone give me some help?

Thanks in advance for the help, Best regards!

+8  A: 

You can use a regular expression or some manual string fiddling, but I think I prefer:

date("d/m/Y", strtotime($str));
Michael Mrozek
I find on a lot of our servers (operating on Australian time) I need to use: date("d/m/o", strtotime($str)); -> i.e 'o' for the year.
niggles
Hi there!I have already tried your solution but does not seems to work. Like I asked on my post, I just need the date in the dd/mm/yyyy format without the time component.Thanks for the help, Best regards!
Rui Gonçalves
Which part doesn't work? `strtotime("2010-04-19 18:31:27");` returns the seconds since the epoch, `1271716287` (for my TZ). `date()` takes a format string and an epoch int; the format string tells it what to return, and "d/m/Y" is days as a zero-padded int, months as a zero-padded int, and year as four digits. Since no time parameters are included in the format string (e.g. "d/m/Y h:i:s"), they won't be returned
Michael Mrozek
Hi there!I was commiting an error with the application of the suggested solution. It worked just fine! To all others, thanks for the responses.Thanks again for the response!Best regards
Rui Gonçalves
A: 

There is also the DateTime object if you want to go that way: http://www.php.net/manual/en/datetime.construct.php

SeanJA
+1  A: 

If your date is in the format of a string use the explode function

array explode ( string $delimiter , string $string [, int $limit ] )

In the case of your code

$length = strrpos($oldDate," ");
$newDate =  explode( "-" , substr($oldDate,$length);
$output = newDate[2]."/".newDate[1]."/".newDate[0];

I have not tested this particular snippet of code for bugs, but usually I use code very similar to this

Grue
This is far more complex of a solution than what is needed.
webdestroya
You're probably right
Grue
A: 
<?php

$test1='2010-04-19 18:31:27'; echo date('d/m/Y',strtotime($test1)); ?>

try this

Murali Krishna kilari
Sorry but your link(?) does not seems to work!
Rui Gonçalves