Split MySQL Date into different Variables

Hi, I am sure this is a simple thing to do but i am having a brain fade moment. I need to split the Date held in a MySQL field (Date), so that i can get teh year/month/day elements of the field into different variables to work with in PHP.

Currently am tryign to use


function ukdateyear($fulldate)
{
	$datearray = str_split($fulldate);
	$year = $datearray[0].$datearray[1].$datearray[2].$datearray[3];
	
	return $year;
}

with little sucess, i think maybe because Date in MySQl is not a string!?!

any help appreciated.


list($year, $month, $day)=explode('-', $fulldate);

:slight_smile:

So that create 3 variables ($year, $month, $date) when the explode encounters a ‘-’ in the variable $fulldate?

exactly

thank you very much - much easier than whereever i was heading off to!

You could also use the date functions in PHP:


return date('Y', strtotime($fulldate));

Edit>>
Oops, I didn’t read your post properly. I thought you only wanted the year…
Er, Remon’s solution is best :slight_smile:

or the ones in mysql:

YEAR()
MONTH()
DAYOFMONTH()

Implemented and works perfectly, ty!