fesan Posted January 28, 2008 Share Posted January 28, 2008 Hi! I'm sure this is a stupid question but I've read my eyes out and still cant figure it out! I have a form where i among other data fill in a date. This is a regular textbox. How do i get this date into my MySQL Table? my date variable looks like this: $date = "28.01.2007"; My collumn date is a date collumn. I also know that MySQL onlu supports date form 2007-01-28, but even when i make my variable: $date "2007-01-28"; it wont work. How do i in the correct way insert a date to my MySQL database from a single textbox in a form? also tried to convert 3 textboxes(y-m-d) in to php date() function and then insert it into my database still no luck. Quote Link to comment https://forums.phpfreaks.com/topic/88228-date-from-a-form-into-mysql/ Share on other sites More sharing options...
tapos Posted January 28, 2008 Share Posted January 28, 2008 check this $date = "28.01.2007"; $n_date = date('Y-m-d',strtotime($date)); echo $n_date Hope u get ur answer Quote Link to comment https://forums.phpfreaks.com/topic/88228-date-from-a-form-into-mysql/#findComment-451434 Share on other sites More sharing options...
MatthewJ Posted January 28, 2008 Share Posted January 28, 2008 Not sure if it will make a difference... but it should be date('Y-m-d') capital "Y" instead of lower case, that would return YYYY-MM-DD date('y-m-d') returns YY-MM-DD which is not the format for a MySQL date field. Matt Quote Link to comment https://forums.phpfreaks.com/topic/88228-date-from-a-form-into-mysql/#findComment-451464 Share on other sites More sharing options...
hitman6003 Posted January 28, 2008 Share Posted January 28, 2008 Force your users to always enter the date in the same format, then use mysql's str_to_date function... http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date Or, use php's date functions if you choose. Either way, strtotime is unreliable at best with changing date formats... Using your format (xx.xx.yyyy) as an example, it can only guess what "1.11.2007" is...November 1st, or January 11th? Users may not always use the same format by default, so you have to force them to. Quote Link to comment https://forums.phpfreaks.com/topic/88228-date-from-a-form-into-mysql/#findComment-451508 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.