Format any date according to WordPress date formatting settings

Format any date you like according to the date formatting settings in the WordPress backend with this simple piece of code. Put the following function in your theme’s functions.php file and enjoy the magic anywhere in your theme.

// $date is in yyyy-mm-dd format
function any_date($date = '2011-10-28')
{
  $format = get_option('date_format');
  return apply_filters('get_the_time', mysql2date($format, $date), $format); 
}