Skip to content

Instantly share code, notes, and snippets.

@nachopants
Created September 24, 2014 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nachopants/3b8a9fd27ee0d63fb65e to your computer and use it in GitHub Desktop.
Save nachopants/3b8a9fd27ee0d63fb65e to your computer and use it in GitHub Desktop.
Preservation Age
<?php
/*
Date of Birth - Preservation Age
Before 1 July 1960 - 55
1 July 1960 to 30 June 1961 - 56
1 July 1961 to 30 June 1962 - 57
1 July 1962 to 30 June 1963 - 58
1 July 1963 to 30 June 1964 - 59
After 30 June 1964 - 60
*/
if (($ts = strtotime($dateOfBirth)) !== false)
{
$age = 55;
$preservationAge = 60;
for ($year = 1960; $year < 1965; $year++)
{
$min = strtotime('1 July ' . $year);
$max = strtotime('+1 year', $min);
($ts < $min && $year == 1960 || ($ts >= $min && $ts < $max)) ? $preservationAge = $age : $age++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment