Jump to content

Archived

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

MartinaL

Change MySQL date output in PHP page

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.