I have a quick question regarding the values returned form MySQL.
Within one of my tables, I have a column assigned the date
data type. When information is inserted into the database, curdate()
is automatically executed to insert the proper date.
That said, MySQL recognizes that value is a date. I have a php script that pulls that value and presents it to the user. Now, is that value a string from php's standpoint?
What I want to do is, if necessary I should say, use the pulled value and insert that into a new table (ex: 10/1/12 pulled by php and then inserted into a new table). If that's the case, can I simply put that value into the new table's column that is of data type date
? Or will MySQL not recognize that as a date?
Any insight is appreciated.
MySQL is smart enough to cast strings into a date. The string should be able to be just about any standard format and it will translate it properly.
EDIT: Sorry, I was incorrect.
You can use PHP or MySQL date parsing functions to handle this. In PHP:
date("Y-m-d", strtotime($row['myDateField']));
Here is a list of valid date strings that strtotime can interpret: http://www.php.net/manual/en/datetime.formats.date.php