E.g. given:
$quarter1 = 4;
$year1 = 2011;
$quarter2 = 3;
$year2 = 2012;
I need to know that the second set are in the future compared to the first set.
I did think this could be done by literally appending the quarter onto the year. e.g.
$qy1 = 20114;
$qy2 = 20123;
// $qy1 < $qy2
But I’m sure this is not a reliable way to compare the two. Is there a better, more reliable way?
Many thanks
Nothing wrong with your method, other than having to do a few string concatenations and typecasting back to int. It could fail, however, if you fail to force the values back to integers, and you’re comparing years with different string lengths, e.g.:
String 9994 will compare as larger than string 10011.
Purely as an alternative, this would work as well, keeping things purely numeric: