Have a Snippet?

Keep, track and share your code snippets with your friends

PHP: Convert a date from SQL to RFC822 format Share on Vkontakte

Convert a date from SQL to RFC822 format. It may be useful for creating RSS-feed.

function sql_to_rfc822($sql_date_str) {
    $d1 = explode(" ", $sql_date_str);
    $d2 = explode("-", $d1[0]);
    $d3 = explode(":", $d1[1]);
    $rfc822_date_str = date("D, d M Y H:i:s", mktime($d3[0], $d3[1], $d3[2], $d2[1], $d2[2], $d2[0])) . "  GMT";
    return $rfc822_date_str;
}


Tag: PHP, DateTime, Date Routines, RFC 822

2 Comments

  1. Avatar
    winbackgo

    11th May 2013, 15:02

    Shit code.
    date(DATE_RFC8, strtotime('2012-10-04 12:41:05'))

  2. Avatar
    RedOctober

    11th May 2013, 15:23

    Of course, your version is better and easier than mine. But perhaps the original code will teach someone to work with the mktime function :)