views:

66

answers:

2

Hello all,

I'm trying to store the date in an sql table, but I want it formatted as such:

Month day, year October 10, 2010 But whenever I do the sql call, the 2010 gets lost. How can I fix this?

$eventdate = "October 10, 2010";
$sql = "INSERT INTO `tims`.`blog` ( `title`, `date`, `post`, `author`, `approved`) \n"
            . "VALUES (
                '" . mysql_real_escape_string($_REQUEST['title'])     . "',
                '" . mysql_real_escape_string(addslashes($eventDate)) . "',
                '" . mysql_real_escape_string($_REQUEST['TextArea1']) . "',
                '" . mysql_real_escape_string($_REQUEST['author'])    . "', 'False')\n";

//echo $sql;
$qry = mysql_query($sql) or die(mysql_error());
+3  A: 

I agree with the rest, you must use the date column in a table for the record and then then you have to display it in your application , you just format the retrieved date as you want like "October 10, 2010". Please do not store the date as varchar text, relational database have the simplicity to store date for you and with SQL you can format the date anyway you like to display it.

Adnan Anwar
+1: For sanity, knowing what should be left to presentation.
OMG Ponies
+1  A: 

Check the column width. You need a VARCHAR(n) as the data type for that column and n needs to be the length of the longest month name of the year + 9. It's not a good idea to store dates this way if you every want to index or sort them, but it should work.

To see the table structure:

show create table `tims`.`blog`;
PMV
Thank you. That was my problem, I hadn't made the VARCHAR long enough.Is there any harm in making it longer than T'll ever need? like say 255, is the database gonna use more memory or anything?
TechplexEngineer
I generally make my varchar columns 3x the size I expect them to need. Not sure if this is frowned upon though.
PMV