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 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'] 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 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. 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. 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
Archived
This topic is now archived and is closed to further replies.