Pretty UK Vehicle registration years

If you’ve ever wanted to convert a date of a UK vehicle into a nice looking representation of the year code then you’ve came to the right place!

I’ve written a small PHP function to convert a given date to one of the following formats:

  • Dates before Feb 1963

    • [YEAR]
    • i.e. “1960″, “1962″
  • Dates from Feb 1963 – August 2001

    • [SUFFIX/PREFIX LETTER] ([YEAR])
    • i.e. “V (1999)”, “A (1983)”
  • Dates from September 2001 onwards

    • [AGE IDENTIFIER] ([YEAR])
    • i.e. “57 (2007)”, “57 (2008)”, “60 (2010)”

/* getRegistrationCode *********************************************
 * Get the age identifier from a UK vehicle registration plate from
 * a given date.  Returns the identifier as a string with the year
 * of registration in brackets.
 * 
 * $registrationDate    The date of registration to be converted
 * 
 * return                String representation of the registration
 *                         date
 ******************************************************************/
function getRegistrationCode( $registrationDate ) {
    $reg      = $registrationDate;
    
    $year     = (int) date( "Y", strtotime( $registrationDate ) );
    $month    = (int) date( "n", strtotime( $registrationDate ) );
    $date     = date( "Y-m-d", strtotime( $regestrationDate ) );

    /* < FEBRUARY 1963 *********************************************
     * If the registration year is 1962 or before then just return
     * the year
     **************************************************************/
    if( $date < "1963-02-01" ) {

        $reg    = "".$year;

    /* FEBRUARY 1963 - AUGUST 2001 *********************************
     * For registrations from 1963 to August 2001 look up the
     * appropriate registration letter
     **************************************************************/
    } elseif( $date <= "2001-08-31" ) {
    
        $yearLetters    = array(
            "1963-02-01"    => 'A',    // 1 Feb 1963 – 31 Dec 1963
            "1964-01-01"    => 'B',    // 1 Jan 1964 – 31 Dec 1964
            "1965-01-01"    => 'C',    // 1 Jan 1965 – 31 Dec 1965
            "1966-01-01"    => 'D',    // 1 Jan 1966 – 31 Dec 1966
            "1967-01-01"    => 'E',    // 1 Jan 1967 – 31 Jul 1967
            "1967-08-01"    => 'F',    // 1 Aug 1967 – 31 Jul 1968
            "1968-08-01"    => 'G',    // 1 Aug 1968 – 31 Jul 1969
            "1969-08-01"    => 'H',    // 1 Aug 1969 – 31 Jul 1970
            "1970-08-01"    => 'J',    // 1 Aug 1970 – 31 Jul 1971
            "1971-08-01"    => 'K',    // 1 Aug 1971 – 31 Jul 1972
            "1972-08-01"    => 'L',    // 1 Aug 1972 – 31 Jul 1973
            "1973-08-01"    => 'M',    // 1 Aug 1973 – 31 Jul 1974
            "1974-08-01"    => 'N',    // 1 Aug 1974 – 31 Jul 1975
            "1975-08-01"    => 'P',    // 1 Aug 1975 – 31 Jul 1976
            "1976-08-01"    => 'R',    // 1 Aug 1976 – 31 Jul 1977
            "1977-08-01"    => 'S',    // 1 Aug 1977 – 31 Jul 1978
            "1978-08-01"    => 'T',    // 1 Aug 1978 – 31 Jul 1979
            "1979-08-01"    => 'V',    // 1 Aug 1979 – 31 Jul 1980
            "1980-08-01"    => 'W',    // 1 Aug 1980 – 31 Jul 1981
            "1981-08-01"    => 'X',    // 1 Aug 1981 – 31 Jul 1982
            "1982-08-01"    => 'Y',    // 1 Aug 1982 – 31 Jul 1983
            "1983-08-01"    => 'A',    // 1 Aug 1983 – 31 Jul 1984
            "1984-08-01"    => 'B',    // 1 Aug 1984 – 31 Jul 1985
            "1985-08-01"    => 'C',    // 1 Aug 1985 – 31 Jul 1986
            "1986-08-01"    => 'D',    // 1 Aug 1986 – 31 Jul 1987
            "1987-08-01"    => 'E',    // 1 Aug 1987 – 31 Jul 1988
            "1988-08-01"    => 'F',    // 1 Aug 1988 – 31 Jul 1989
            "1989-08-01"    => 'G',    // 1 Aug 1989 – 31 Jul 1990
            "1990-08-01"    => 'H',    // 1 Aug 1990 – 31 Jul 1991
            "1991-08-01"    => 'J',    // 1 Aug 1991 – 31 Jul 1992
            "1992-08-01"    => 'K',    // 1 Aug 1992 – 31 Jul 1993
            "1993-08-01"    => 'L',    // 1 Aug 1993 – 31 Jul 1994
            "1994-08-01"    => 'M',    // 1 Aug 1994 – 31 Jul 1995
            "1995-08-01"    => 'N',    // 1 Aug 1995 – 31 Jul 1996
            "1996-08-01"    => 'P',    // 1 Aug 1996 – 31 Jul 1997
            "1997-08-01"    => 'R',    // 1 Aug 1997 – 31 Jul 1998
            "1998-08-01"    => 'S',    // 1 Aug 1998 – 28 Feb 1999
            "1999-03-01"    => 'T',    // 1 Mar 1999 – 31 Aug 1999
            "1999-09-01"    => 'V',    // 1 Sep 1999 – 29 Feb 2000
            "2000-03-01"    => 'W',    // 1 Mar 2000 – 31 Aug 2000
            "2000-09-01"    => 'X',    // 1 Sep 2000 – 28 Feb 2001
            "2001-03-01"    => 'Y',    // 1 Mar 2001 – 31 Aug 2001
        );
        
        // Loop through the letters until we hit a date that's after
        // our registration date
        foreach( $yearLetters as $key => $letter ) {
            $reg    = $letter." (".$year.")";
            if( $key > $date )
                break;
        }
    
    /* SEPTEMBER 2001 ONWARDS **************************************
     * For registrations since September 2001 use the current
     * 00 - 99 numbering scheme based on the year.
     **************************************************************/
    } else {
        
        /* CALCULATE THE REG CODE **********************************
         * New style registration years run from the start of March
         * to the end of February of the next year.
         * 
         * The two digit year value represents the March - August
         * identifier (i.e. 09, 10) and 50 is added to the year for
         * the September - February identifier (i.e. 59, 60).
         * 
         * To calculate the registration code we must follow the 
         * steps below:
         *     - YEAR % 50
         *     - if MONTH < 3 subtract 1
         *     - Add 50 if MONTH > 8 or MONTH < 3
         * 
         * Giving us:
         * ( YEAR % 50 ) + ( ( MONTH < 3 ) ? 49 : ( MONTH > 8 ) ? 50 : 0 )
         */
        $reg = ( $year % 50 ) +
        		( ( $month < 3 ) ? 49 : ( ( $month > 8 ) ? 50 : 0 ) );
        $reg = str_pad( $reg, 2, "0", STR_PAD_LEFT )." (".$year.")";
        
    }
    
    return $reg;
}

The function above should convert all dates since 1963 to codes. It should also hold true for the future as the current partern is a 50 year repeating one (lest they change it of course).
- Chris