Jump to content

Change MySQL date output in PHP page


MartinaL

Recommended Posts

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.

[code]<?php

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

?>[/code]

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.
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]

[code]
SELECT DATE_FORMAT(lastDate, '%M %D') AS formatted_date
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.