Jump to content

Putting date into database as month name and year.


davidcriniti

Recommended Posts

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')";

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.