Jump to content

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


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.

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.