I have a Date of Birth field and trying to use the timespan function to get the age, but returns "28 Years, 2 Months, 2 Weeks, 3 Days, 15 Hours, 16 Minutes".
Any idea how I can just get the "28 Years" part?
Thanks!
I have a Date of Birth field and trying to use the timespan function to get the age, but returns "28 Years, 2 Months, 2 Weeks, 3 Days, 15 Hours, 16 Minutes".
Any idea how I can just get the "28 Years" part?
Thanks!
$date = '28 Years, 2 Months, 2 Weeks, 3 Days, 15 Hours, 16 Minutes';
This will give you "28 Years"
$yearsPart = substr($date, 0, strpos($date, 'Years') + 5);
So will this:
$parts = split(', ', $date);
$yearsPart = $parts[0];
I suggest you use PHP's strftime() function. Instead of using the CI's timespan().
echo strftime('%Y', 1226239392);