1. I'm trying to use the date() function to format a date that is stored in a MySQL database, but no matter what date is stored in the database, it keeps returning 12-31-1969. The correct date to be returned is 08-27-2004. The code that I'm using is:
2. The MySQL date format is yyyy-mm-dd, but in the US most people are used to the dd-mm-yyyy format. Can I do something with the input field to accommodate this format?
DATE_FORMAT is the function you probably want for #1.
As for 2, you can use a regular expression to capture the individual numbers and transform them into a date string for timestamp. However, I believe most of us don't accept dates directly like this, because there are hundreds of formats. I opt for having drop downs for day and month, and a textbox for year when I want a date from the user.
Thanks, feyd - I'll use DATE_FORMAT as suggested for #1.
For #2: When you use the drop downs and textbox for the dates, how do you correctly format the input to add it to the database? Do you have a separate field for each component of the date?
What I didn't mention before is that I am currently using NOW() to get the date.
$query = "INSERT INTO table (order_date) VALUES (NOW())";
Although I've checked the PHP manual, I can't find information on how to properly re-format the above in order to get the database to accept the information in the correct format.
Obviously I need to change the coding to get the database to accept the three variables - month, day, year - as one date, which is the field "order_date" in my database. I should change the (NOW()) to what?
I've never done this before, and I don't expect you to do it for me, but I haven't been able to locate what I'm looking for here or in php.net. If you could just point me in the right direction...
Now that I've made the changes to the database structure to start working on the dates, something has gone awry with my order_no field, which is the primary key.
It is an auto-incremented field, but now it wants to keep assigning the number 127 to every order that is submitted, and I get the error message
Duplicate entry '127' for key 1.
The only thing I changed in the database was deleted the "order_date" field and added "month", "day" and "year".