...

View Full Version : Stuck, how can you return JUST the last 2 digits of a year?



skcin7
02-25-2010, 09:20 PM
Hi all. I have a function which I am writing which takes a datetime as its parameter, and I want it to return a 2 digit representation of year, but I can't figure out for the life of me how to do this! Can anybody tell me what I need to do with my code to get this to work? Thanks!

This is what I have so far



function datetimeGetYear($datetime)
{
$year = explode("-", $datetime); // 4 digit representation of year is now stored in $year[0]

return $year[0]; // Stub... I need this to return a 2 digit representation of the year, not a 4 digit.
}

JAY6390
02-25-2010, 09:38 PM
function datetimeGetYear($datetime)
{
$year = explode("-", $datetime);
return substr($year[0], -2);
}

skcin7
02-25-2010, 09:45 PM
Thank you!!! :-)

bcarl314
02-25-2010, 09:55 PM
Or, you could use PHPs native functionality...



$year_2d = date("y",strtotime($datetime));



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum