Jump to content

[SOLVED] Convert YYYY-DD-MM to display in a more readable format?


outchy

Recommended Posts

Not sure if this question belongs here or in the MySQL section but I think it goes here...

 

Let's say I have a MySQL database entry that is a date in YYYY-DD-MM format.  Is there a way to take that date and display it in a more readable format (say 'January 1, 2008') on a php webpage?

I guess the guy wants to display an existing date. You can use this:

 

<?php
$date = '2008-08-17'; //mysql uses YYYY-MM-DD if you're using the mysql date data type
list($year, $month, $day) = explode('-', $date); //get individual variables for year, month and day
echo date('F j, Y', mktime(0, 0, 0, $month, $day, $year)); //print the date using a custom format
?>

$date = date("F n, Y");

 

and then just insert into database

 

NO! NO! NO! That would be a totally useless format to store in a DB.

 

Always format on output, by using one of either

- MySQL's DATE_FORMAT() function

- PHP's date() function

 

I guess the guy wants to display an existing date. You can use this:

 

<?php
$date = '2008-08-17'; //mysql uses YYYY-MM-DD if you're using the mysql date data type
list($year, $month, $day) = explode('-', $date); //get individual variables for year, month and day
echo date('F j, Y', mktime(0, 0, 0, $month, $day, $year)); //print the date using a custom format
?>

 

Okay, could you tell me how I would apply this code to my particular case (which is a simple concert database)?  And yes, I am trying to pull out the "dateofshow' variable from the database and display it as 'January 1, 2008' or something like that.

 

Here are the three relevant .php files in plain text:

 

http://www.warehamps.org/nik/index.txt

 

http://www.warehamps.org/nik/insert.txt

 

http://www.warehamps.org/nik/add.txt

 

Thanks for all your help.

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.