I think the most common problem with any new language is understanding how the dates are formatted. I'm making my first PHP website and trying to insert a date into MySQL but just can't seem to find an example of how to do it anywhere.
Here is what I have so far
When I execute the statement it succeeds but I get a record likeCode:if (isset($_REQUEST['txtDate'])) { $dt = split ("/",$_REQUEST['txtDate']); $MonthValue = $dt[0]; $DayValue = $dt[1]; $YearValue = $dt[2]; if (checkdate($MonthValue,$DayValue, $YearValue)) { $insertrecord = "Insert into tblTime (CategoryId, DateCreated) values { $insertrecord .= $_REQUEST['selCategory']; $insertrecord .= ", "; $insertrecord .= date('Y-m-d', strtotime($_REQUEST['txtDate'])); $insertrecord .= ")"; } } }
Category = 1
DateCreated = 0000-00-00
The first part of the code validates the date entered to ensure it is valid so I know that I have a valid date + I entered it so I know it is valid. It passes the validation test but I have tried about a dozen different ways of formatting the date to enter it and it just does not make it into the database.
I'm sure there is someone out there who has entered a date other than the current time into a MySQL database but unfortunately there are no references to this problem anywhere on the internet.




Reply With Quote