john.woolley Posted April 16, 2014 Share Posted April 16, 2014 Hi all Please excuse the newbie question, but am struggling a little. I'm reading the book and I'm also trying to put the practical lessons into play chapter by chapter into my own project. Hence the question. I've a form with a 'Date of Birth Field' - now I'm in the UK and the format is DD/MM/YY. In MySQl it's YY/MM/DD right? How do I get it to reverse the date? Thanks in advance.. Link to comment Share on other sites More sharing options...
HartleySan Posted April 16, 2014 Share Posted April 16, 2014 Hello, and welcome to the forums. Does this link answer your question: http://stackoverflow.com/questions/10306999/php-convert-date-format-dd-mm-yyyy-yyyy-mm-dd Link to comment Share on other sites More sharing options...
john.woolley Posted April 16, 2014 Author Share Posted April 16, 2014 update to this. I've tried using the php function date_format($STRING IM USING, YY/MM/DD). I get the SQL error that there's also a time stamp expected. I've thought about creating three fields on the form. Year, Month, Date - then concatenating the results into a single string to put into the database. That seems to have a long code base though. Firstly, validating that each of those fields isn't empty; is numeric and then finally bundling them all together. Would welcome ideas Link to comment Share on other sites More sharing options...
HartleySan Posted April 16, 2014 Share Posted April 16, 2014 Did you check out the SO thread I linked to? Link to comment Share on other sites More sharing options...
john.woolley Posted April 16, 2014 Author Share Posted April 16, 2014 Yes thanks I did. I managed to get the code working in the end; but then I figured it was also open to a number of problems. So I created 3 select fields. Date / Month / Year. Then made this code if ($_POST['udobdate'] == '' && $_POST['udobmonth'] == '' && $_POST['udobyear'] == '') { $errors[] = 'You forgot to enter your Date of Birth.'; } else { $udob = $_POST['udobyear'] . '/' . $_POST['udobmonth'] . '/' . $_POST['udobdate']; $dob = mysqli_real_escape_string($dbc, $udob); } That's done the trick. I'll probably refine it a little more but in terms of functionality - works a treat. Now I'm trying to figure out cookies and sessions that lovely Warning: Cannot modify header information. problem. Even when the cookie is at the top of the page - before any code. Unless of course I'm misunderstanding the book. Link to comment Share on other sites More sharing options...
HartleySan Posted April 16, 2014 Share Posted April 16, 2014 Glad you came up with a solution. A solution is better than no solution. You cannot send or modify headers after something (even a single space) has been output to the screen. I can't really help you without more details though. Link to comment Share on other sites More sharing options...
john.woolley Posted April 16, 2014 Author Share Posted April 16, 2014 Thanks HartleySan - I've started a new thread for this question Link to comment Share on other sites More sharing options...
HartleySan Posted April 16, 2014 Share Posted April 16, 2014 Just answered it there. Link to comment Share on other sites More sharing options...
Recommended Posts