I have to use the sprintf since this string is actually quit larger with many other string variables. etc… but all I get is the incorrect date of 1969-12-31 and 1969-12-31 respectfully in MYSQL. The date was gotten from a form variable where DATEAA and DATEBB are assigned a date chosen by the user. In this case it was 1/10/2009 and 7/12/2012. Of course the date really doesnt matter I am just showing the format.
I have tried many things form this forum and every other but can’t get passed the error from string to a date in the database.
I tried this solution posted in this forum "$date = mysql_real_escape_string($_POST[‘date’]);
$date = implode(‘-’, array_reverse(explode(‘-’, $date))); " and many many others but all that occurs with this one is the the date in the database goes to 0000-00-00.
OK COOL some progress now I get 1309759200 and 1354345200 which I can see is going to need to be converted back when I place it back on the screen. Let me go to the documents and see what I need to do to do that?
In case you want to format the date the way it was entered by the user (7/12/2012), use date(‘n/j/Y’, $DateAA);
n = numeric month without leading 0
j = day of the month without leading 0
Dates are stored in the database by entering them in as CCYY-MM-DD - the internal format is different and you can have it formatted however you want when you extract it from the database. The only limitation is on what format it has to be in when you store it.
Never use any type of field other than date or timestamp to store a date as if you use anything else you lose most of the date processing functionality built into the database.
Well the problem set I ran into would not work any other way?
So what direction can you point me to make sure that I can store it in the DB as a date field since it is has gone from a string variable at the form level then converted to an integer in order to store it at the DB level? Now I would like it as a date variable in the DB so that way I can do against it at the server level. (Which is the very thing I want to do for the application I am writing.) Currently if I store it as a integer 10 I have to add an extra step when I run a database procedure against it to do the math required in the application. (Something I actually am seeing as a problem.)
Any direction of how I can store a string that is formatted as a date first then needs to be converted into a date so that it can be imported using a sprint with MYSQL would be greatly appreciated. I have tired almost every hybrid in every help I could find.
If using - doesn’t work that means that $_POST[‘DateAA’] doesn’t contain a valid timestamp that you are converting into a date. Your visitors are not likely to know how to enter a timestamp and are more likely to enter the date in some other format so most likely you need to convert $_POST[‘DateAA’] into a timestamp BEFORE using it in the date function in order to get the code to work
Solved it using the original DATE variable in MYQL. Thanks everyone who helped me with an intermediate solution which gave me some pice of mind and then pushed me into the right direction!