Jump to content


Photo

Change MySQL date output in PHP page


  • Please log in to reply
2 replies to this topic

#1 MartinaL

MartinaL
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 March 2006 - 11:19 PM

I have some information which I am displaying on a PHP page from a MySQL database.

One of them is a date and it comes back in the format 2006-03-17, but I want it to display to the screen in the format 17 March. Is this possible?


#2 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 17 March 2006 - 12:53 AM

Yes. You could enter it into the table as a text field instead of a date field and submit it in the format you wish it to display or you could change it once you retrieve it from the database.

<?php

$date = "2001-01-05";
echo date('M d, Y', strtotime($date));

?>

I don't know what your variable name is that gets the date from your database, so just replace $date in the echo line with your date variable name and change the echo to whatever it is you need to do with it.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#3 Steveo31

Steveo31
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSan Jose, CA

Posted 17 March 2006 - 01:09 AM

Or you could use the MySQL DATE_FORMAT function. Less PHP work.

[a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a]

SELECT DATE_FORMAT(lastDate, '%M %D') AS formatted_date






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users