Dibley
May 25, 2011, 11:14am
1
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.
rpkamp
May 25, 2011, 11:16am
2
list($year, $month, $day)=explode('-', $fulldate);
Dibley
May 25, 2011, 11:20am
3
So that create 3 variables ($year, $month, $date) when the explode encounters a ‘-’ in the variable $fulldate?
Dibley
May 25, 2011, 11:24am
5
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
Dibley
May 25, 2011, 11:47am
8
Implemented and works perfectly, ty!