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!
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!
You can use a regular expression or some manual string fiddling, but I think I prefer:
date("d/m/Y", strtotime($str));
There is also the DateTime
object if you want to go that way: http://www.php.net/manual/en/datetime.construct.php
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
<?php
$test1='2010-04-19 18:31:27'; echo date('d/m/Y',strtotime($test1)); ?>
try this