Here is a more complicated version of this script that will accept a date, a date format and output formatted date where you can use %O as a placeholder for the ordinal in the format: http://pastebin.com/xZ1afqqC.