t4newman Posted March 19, 2010 Share Posted March 19, 2010 I'm inserting a row of data into a MySQL database and all of the data except two dates correctly get added to the row. I know what the problem is but I'm not sure of the solution... I'm getting a user to input UK format dates (location of users) but the database is showing 0000-00-00 which I suspect is because it is only recognising US format dates (YYYY-MM-DD). I'm using date_default_timezone_set($zondatetime); and feeding that variable with 'Europe/Paris' but it's not making any difference. Any help very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/195822-help-posting-dates-from-php-code-into-mysql-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 19, 2010 Share Posted March 19, 2010 Actually, YYYY-MM-DD is not a US format. It is a left-to-right, most significant (year) to least significant (day), format that allows dates to be compared and sorted correctly. There are several methods that you can use to changed the format from what is being entered into the expected format. Two of the fastest are - 1) After you validate the entered date, use explode to break the date into its separate fields, then put the pieces back together in the correct format, 2) After you validate the entered date, use the mysql STR_TO_DATE() function directly in your query to produce a DATE value from the entered value. date_default_timezone_set() only sets the time zone that the php functions like date(), mktime(), strtotime()... use. It has no effect on what your code does with the data it receives. Quote Link to comment https://forums.phpfreaks.com/topic/195822-help-posting-dates-from-php-code-into-mysql-database/#findComment-1028672 Share on other sites More sharing options...
Jaguar Posted March 19, 2010 Share Posted March 19, 2010 The date_default_timezone_set() function doesn't change the format you have to use for inserts. You will have to reformat the users input. Quote Link to comment https://forums.phpfreaks.com/topic/195822-help-posting-dates-from-php-code-into-mysql-database/#findComment-1028674 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.