Jump to content

Extracting date from MySQL DB into three variables


Go to solution Solved by ade2901,

Recommended Posts

Hi,

 

I wonder if someone can help me...

 

I am trying to extract the date into three different variables ready to go into three option boxes for the user to update a person's date of birth. 

 

I am using the following to split up the day, month and year:

 

$queryDate = mysql_query("SELECT YEAR(playerDOB), MONTH(playerDOB), DAY(playerDOB) FROM player WHERE playerID='$playerID'") or die (mysql_error());

 

Now I have tried this within the database and can see that it splits it up. The problem I am having is being able to access them in variables. How do I go about accessing the year, day and month separately from the $queryDate variable?

 

Appreciate the help in advance!

  • Solution

Solved using a different method I decided to try...

 

Here is the solution:

$query = mysql_query("SELECT * FROM tableName WHERE ID='$ID'")or die(mysql_error());
			
			$row = mysql_fetch_array($query);
			
			
			/*Player DOB Exploding*/
			$year = date('Y', strtotime( $row['dateColumn'] ) );
			$month = date('m', strtotime( $row['dateColumn'] ) );
			$day = date('d', strtotime( $row['dateColumn'] ) );
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.