I need to calculate at which year a school class has started, given the year they currently are in. For example a class of 2nd graders have started school in 2013, if I pass 2 to the function it should return 2013.
So, I need to take x years and 6 months out of a date, I was wondering which is the better way to do it.
Using strtotime()
:
function school_started1($years){
return date('Y', strtotime('now - '.$years.' year - 6 month'));
}
Or calculating it manually:
function school_started2($years){
$seconds_in_half_a_year = 365.25 * 43200;
return date('Y', time() - $years * 365.25 * 86400 - $seconds_in_half_a_year);
}
I'm thinking the second method would be better because it doesn't have to do any parsing and stuff ( not quite a fan of parsing ). I can do the math myself, are there any benefits/downsides to using strtotime
? What do you think?