dreampho Posted March 2, 2012 Share Posted March 2, 2012 Hi. I have an input field where a date is entered, format dd-mm-yy. I need to query the database to see if this date exists. How can I convert the date to yyyymmdd before the query? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258098-convert-date-format-from-form-input-before-query/ Share on other sites More sharing options...
creata.physics Posted March 2, 2012 Share Posted March 2, 2012 print str_replace( '-', '', 'yyyy-mm-dd'); Of course you'll need to replace 'yyyy-mm-dd' with the appropriate key for the post data, e.g. $_POST['date'] Quote Link to comment https://forums.phpfreaks.com/topic/258098-convert-date-format-from-form-input-before-query/#findComment-1323037 Share on other sites More sharing options...
dreampho Posted March 2, 2012 Author Share Posted March 2, 2012 Sorry, I dont understand. print str_replace( '-', '', '$_POST[date]'); This just displays $_POST[date] I am being thick ha ha Quote Link to comment https://forums.phpfreaks.com/topic/258098-convert-date-format-from-form-input-before-query/#findComment-1323038 Share on other sites More sharing options...
darkfreaks Posted March 2, 2012 Share Posted March 2, 2012 $date= $_POST['date']; $new_date = date('d-m-y',strtotime($date)); then insert $new_date into your query. Quote Link to comment https://forums.phpfreaks.com/topic/258098-convert-date-format-from-form-input-before-query/#findComment-1323047 Share on other sites More sharing options...
dreampho Posted March 2, 2012 Author Share Posted March 2, 2012 Thank you, thats what I was looking for. Quote Link to comment https://forums.phpfreaks.com/topic/258098-convert-date-format-from-form-input-before-query/#findComment-1323056 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.