learningPHP1 Posted April 3, 2014 Share Posted April 3, 2014 hello,Trying to convert 2 post variables to strtotime so that it can be saved to a database.The 2 variables are:$testDate = $_POST['date'] ; // containts: 2014-04-22$testTime = $_POST['time']; // containt: 21:02:17echo $date_time = $testDate . $testTime; // result: 6969-1212-3131 19:00:00echo $new_date = date('yy-mm-dd H:i:s', strtotime($date_time)); // result: 6969-1212-3131 19:00:00how do i go about setting the $new_date variable to 2014-04-22 21:02:17 so that it can be saved to a database(mysql data type: datetime)any help you can provide would be greatly appreciated.Thanks Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 3, 2014 Share Posted April 3, 2014 What the heck are those echo statements doing? I've never encountered anyone using them that way before. Please explain. Other than that you should look up the format specs on the date function since yours are definitely wrong. (You get '6969' cause you have a spec that begins with 'yy' which means the last 2 digits of the full year will come out twice.) Quote Link to comment Share on other sites More sharing options...
requinix Posted April 3, 2014 Share Posted April 3, 2014 $testDate = $_POST['date'] ; // containts: 2014-04-22 $testTime = $_POST['time']; // containt: 21:02:17 echo $date_time = $testDate . $testTime; // result: 6969-1212-3131 19:00:00 No, the result is "2014-04-2221:02:17". Which should explain why strtotime() couldn't understand it. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 3, 2014 Share Posted April 3, 2014 There is no need to use date() to reformat the date if your $date_time string is already in the correct format to be handled by your datetime field. The only problem you have is you are not concatenating the $testDate and $testTime variables with a space. $date_time = $testDate . ' ' . $testTime; Quote Link to comment 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.