seed Posted August 22, 2007 Share Posted August 22, 2007 Can someone provide me some insight on how to insert a date into a mysql table. I'm trying to create an events page for a site I've created. I need to allow the user to enter a start & end date. In mysql the fields are of type "date" - (Doesn't have to be that way if you guys suggest otherwise) My form is requesting the date in the format of MM/DD/YYYY. Can someone please provide some insight on how to get that into the mysql field. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 23, 2007 Share Posted August 23, 2007 I'm not sure what you mean... dates should be stored in YYYY-MM-DD format in the database, as long as your form spits out the date in this fashion, you can simply set the value of the field to this. Quote Link to comment Share on other sites More sharing options...
seed Posted August 23, 2007 Author Share Posted August 23, 2007 I figged it out. In my form the date is entered as MM/DD/YYYY so I had to create this bit of code for properly format it for mysql $eventStartDate = $_POST['txtEventStartDate']; $startYear = substr($eventStartDate, 6, 4); $startMonth = substr($eventStartDate, 0, 2); $startDay = substr($eventStartDate, 3, 2); $startDate = $startYear . "-" . $startMonth . "-" . $startDay; insert into tbl_test (col_test) values ('$startDate'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.