davidcriniti Posted January 12, 2011 Share Posted January 12, 2011 Hi, I've got a date picker on a form which puts data into a database in the YYYY-MM-DD format. Just wondering how I could also put the name of the month (extracted from that) as well as just the year into separate columns. Ie: To use the field race_date from the form to also fill the 'race_month' and 'race_year' columns in the database. This code obviously only fills the 'race_date' column so far: global $_POST; $race_date = $_POST["race_date"] ; .... $query = "INSERT INTO 10k_races (race_date, race_month, race_year)" . "VALUES ( '$race_date', '$race_month', '$race_year')"; Quote Link to comment https://forums.phpfreaks.com/topic/224168-putting-date-into-database-as-month-name-and-year/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2011 Share Posted January 12, 2011 also put the name of the month (extracted from that) as well as just the year into separate columns ^^^ That would result in duplicate/redundant information stored in your table and would be a bad design. To get the year and the month name from your race_date column any time you need those values, you would simply use the mysql YEAR() and MONTHNAME() functions in your queries. Quote Link to comment https://forums.phpfreaks.com/topic/224168-putting-date-into-database-as-month-name-and-year/#findComment-1158312 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.