ShaolinF Posted November 26, 2009 Share Posted November 26, 2009 Hi Guys I am having issues converting my user input date into something understandable by the DB. The user inputs a date with the following format DD/MM/YYYY. The DB column is set as follows: course_start_date date How do I convert the user date so that I can insert it into the DB ? I tried strtotime() but that doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/183050-converting-str-date-to-insert-into-db/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 26, 2009 Share Posted November 26, 2009 There are two ways you can do this for the format you have shown - 1) Use the mysql STR_TO_DATE() function in your query, 2) Explode the string on the / character, then form a new string with the fields in the correct format. Unfortunately, the strtotime() function does not understand DD/MM/YYYY, so you would need to alter the string before you could use strtotime() on it. When using the / for a delimiter, you would need to supply a mm/dd/yyyy. See this link for a definition of what strtotime can parse - http://www.gnu.org/software/tar/manual/html_node/Calendar-date-items.html#SEC116 Quote Link to comment https://forums.phpfreaks.com/topic/183050-converting-str-date-to-insert-into-db/#findComment-966087 Share on other sites More sharing options...
ShaolinF Posted November 26, 2009 Author Share Posted November 26, 2009 Thanks. Regarding strtotime() it looks like it does convert the string date but its format isnt being accepted. See error below: [incorrect date value: '1228867200' for column 'course_start_date' at row 1] STR_TO_DATE() seems to be a viable option. However I don't know how to implement it since I am inserting arrays into the DB so I cant really call the STR_TO_DATE() function. $DataArr = array('course_start_date' => $course_date, 'sometype' => 'value'); Quote Link to comment https://forums.phpfreaks.com/topic/183050-converting-str-date-to-insert-into-db/#findComment-966098 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.