An easy, though manual process, is to perform a lookup of the last trading day calendar every year and put that into the database. For Oil, so far the best resource I've found is at http://www.cmegroup.com/
Contract Month: JAN 2012The SQL would look like:
Last Trade Day: 12/20/2011
INSERT INTO
futures_expirations
( id, created_on, updated_on, ticker_symbol, contract_description ,contract_month ,contract_year ,last_trading_day )
VALUES
(
'b360c358-1cb6-408a-81f1-c466dfb7344c' -- A unique identifer
, now() -- Timestamp row was created
, now() -- Timestamp row was updated
, 'cl' -- The base ticker symbol for the future, in this case cl is for oil
, 'crude oil for 2012 jan' -- A description of the contract
, 'f' -- The letter indicating what month this contract is trading for.
, 12 -- The year this contract is trading for.
, to_date('12/20/2011','MM/DD/YYYY') -- When is the last day of trading for this contract
);