Storing Date as a string in MySQL
Posted: Mon May 19, 2003 1:53 pm
Hi!
I need help with the following issue: i'm trying to store the computer's actual date in the 'date_created' colum of a MySQL table.
The code i first tried to do it was:
//first determine actual date
$today=date("d/m/Y",time());
//then i use this query to insert all itens into the table
$insertSQL=sprintf("insert into mytable(col1, col2,...,date_created) VALUES(%s,%d,...,&s)", function1, function2,...,$today);
where col1,col2... are the names of other columns in the table and function1,function2... are functions i use to obtain some other values.
There is no problem with any of these functions, since all fields are correctly inserted in the table, except for the date!
Instead of writing the actual date, the program writes a number, which is the result of this numerical division: d/m/Y. For example, if the date is 19/05/2003 it writes 0.0019 whic is 19 divide by 5 divide by 2003. That is even more strange to me since print of gettype($today) returns string, which is exactly the type of variable i want and the colum (date_created)is suppose to accept.
What must i do to correctly insert dates (like "19/05/2003") in mytable, storing them as a string??
Thanks everybody!
I need help with the following issue: i'm trying to store the computer's actual date in the 'date_created' colum of a MySQL table.
The code i first tried to do it was:
//first determine actual date
$today=date("d/m/Y",time());
//then i use this query to insert all itens into the table
$insertSQL=sprintf("insert into mytable(col1, col2,...,date_created) VALUES(%s,%d,...,&s)", function1, function2,...,$today);
where col1,col2... are the names of other columns in the table and function1,function2... are functions i use to obtain some other values.
There is no problem with any of these functions, since all fields are correctly inserted in the table, except for the date!
Instead of writing the actual date, the program writes a number, which is the result of this numerical division: d/m/Y. For example, if the date is 19/05/2003 it writes 0.0019 whic is 19 divide by 5 divide by 2003. That is even more strange to me since print of gettype($today) returns string, which is exactly the type of variable i want and the colum (date_created)is suppose to accept.
What must i do to correctly insert dates (like "19/05/2003") in mytable, storing them as a string??
Thanks everybody!