TechplexEngineer
TechplexEngineer

Reputation: 1928

store commas in mysql database

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());

Upvotes: 0

Views: 1197

Answers (2)

Parris Varney
Parris Varney

Reputation: 11478

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`;

Upvotes: 1

anwarma
anwarma

Reputation: 2085

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.

Upvotes: 4

Related Questions