reece_1989 Posted July 30, 2009 Share Posted July 30, 2009 Ive got a slight problem that ive been trying to fix for hours and have NO idea at all ?? as you know the mysql db store dates yyyy-mm-dd so ive modified my php coding so it enters dates in the db correctly etc. BUT if the date is 0000-00-00 (i.e. nothing entered) then my site displays random old dates ??? my temp solution was using an if statment so if date = 0000-00-00 then display "" (nothing). problem is when someone uses my update form and doesnt enter anything for date then a random date is put in the db (and then we dont know whther this is real or not) ?? im so stuck! --what ive done so far: --- when displaying dates on my site i want them in UK time so i convert them to time: <? $time = strtotime($date); ?> and then to show on page: echo "$time this works fine! when using an update form in php user enter date in UK format then i convert to time then yyyy-mm-dd -this enters dates into the db perfectly. I dont have a clue Thanks ps. sorry its so confusing but its quite early in the morning Quote Link to comment https://forums.phpfreaks.com/topic/168069-solved-strtotime-function-is-messing-up/ Share on other sites More sharing options...
JonnoTheDev Posted July 30, 2009 Share Posted July 30, 2009 You should set the mysql date field as a NULL field. If a date isn't entered into your form then your sql should insert NULL, not an empty value (SET dateField=NULL). You are correct all dates should be in the format of YYYY-MM-DD. When outputting the date you should check for a value first if($row['dateField']) { $row['dateField'] = date("d-m-Y", strtotime($row['dateField'])); } print $row['dateField']; Quote Link to comment https://forums.phpfreaks.com/topic/168069-solved-strtotime-function-is-messing-up/#findComment-886748 Share on other sites More sharing options...
reece_1989 Posted July 30, 2009 Author Share Posted July 30, 2009 Thanks neil!! Yep ive done that and it works great! I think its mad there isnt an option of doing it any other way...but im happy now :) Quote Link to comment https://forums.phpfreaks.com/topic/168069-solved-strtotime-function-is-messing-up/#findComment-886922 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.