how to format dates using php + mysql

Hi,
I have a mysql database, and using php, i want to format the date in european format, which is dd/mm/yyyy

the dates are being inputed to the database using the curdate function, the current output of a date is

2007-11-27 00:00:00


i need it to be 27/11/2007

thanks
markmchughAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nizsmoConnect With a Mentor DeveloperCommented:
strtotime() as angellll said:
<?php
	$date = "2007-11-27 00:00:00";
	
	echo date("d-m-Y",strtotime($date));
?>

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
markmchughAuthor Commented:
can i do it in php?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Muhammad WasifCommented:
Why you want to do it in PHP? Anyway take a look at this http://www.php.net/manual/en/ref.datetime.php
0
 
nplibCommented:
Change the datetime field to a date field, this will eliminate the 00:00:00 portion of the field.

Then I would format it using PHP, it's slightly faster.

$sql = "select date_field from table;";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs)) {
      $formated_date = date("d/m/Y", strtotime($row['date_field']);
      echo $formated_date;
}
0
 
Muhammad WasifCommented:
@nplib
Is it faster to format the date in PHP rather than MySQL? How?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>can i do it in php?

yes. strtotime() will get the time value from the string yyyy-mm-dd.
then, with the date() function, you can format it to the format you want

0
 
nplibCommented:
@wasifg
just the way sql severs process commands.

I'm not to sure why it is, but I have a table that has 3000+ records, and when I do it with date_format() it takes 0.05 seconds to return all, and when I do it without it takes 0.005 seconds, although both real fast, doing the php way is marginably faster, that's why I said slightly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.