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.
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.