Jump to content

Extracting date from MySQL DB into three variables


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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.