vinoindiamca Posted December 20, 2008 Share Posted December 20, 2008 If User insert date like 12-dec-2008 insert into test values(1,'12-Dec-2008'); it gives error ERROR 1292 (22007): Incorrect datetime value: '12-Dec-2008' for column 'todate' at row 1 please help in this I know mysql date format like 2008-12-12 . but i need '12-Dec-2008' convert to 2008-12-12 this Quote Link to comment https://forums.phpfreaks.com/topic/137817-date-format-help/ Share on other sites More sharing options...
.josh Posted December 20, 2008 Share Posted December 20, 2008 you can use strtotime and date to reformat it, or you could just change your form to send values in the correct format in the first place (i.e.- dropdowns instead of text fields, numeric values for dropdowns instead of string values, etc...) Quote Link to comment https://forums.phpfreaks.com/topic/137817-date-format-help/#findComment-720310 Share on other sites More sharing options...
PFMaBiSmAd Posted December 20, 2008 Share Posted December 20, 2008 Or try the solution you were already given in your existing thread on this problem - http://www.phpfreaks.com/forums/index.php/topic,230893.msg1069970.html#msg1069970 Quote Link to comment https://forums.phpfreaks.com/topic/137817-date-format-help/#findComment-720314 Share on other sites More sharing options...
.josh Posted December 20, 2008 Share Posted December 20, 2008 I suggest doing it through php. You're supposed to be validating user input anyways. For instance, if you're allowing the user to enter in the date from a text field, STR_TO_DATE() is not going to do you a whole lot of good if user entered in something other than a date, or some weird date format that these built in functions don't recognize. Validate user input through php, send it to the db in the proper format. And please do not post multiple topics asking the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/137817-date-format-help/#findComment-720317 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.