in my news db news date is stored as datetime, but in rss feed i need to convert it to RFC822.

0000-00-00 23:23:59 ---> Fri, 23 May 2003 23:23:59 +0100

how to do this?

thanks!

    Look at the [man]date[/man] function and you will see how to format the date as you want.

      Incidentally, RFC822 has been obsoleted by RFC2822, in case that's a stumbling block.

        em, its not so easy.

        if ill use date(r, .. then i need to convert my datetime to timestamp first and then proceed to converting rcf 822

          Not so easy, but almost.

          Among the Date and Time Functions is strtotime():

          $date = '2006-11-11 11:11:11';
          echo date('r', strtotime($date));
          
          // Sat, 11 Nov 2006 11:11:11 -0300

            this was way how i was doing this,

             <?
            list($date,$hours) = split(' ', $row['datetime']);
            list($year,$month,$day) = split('-',trim($date));
            list($hour,$min,$sec) = split(':',$hours);
            echo date(r,mktime($hour, $min, $sec, $month, $day, $year));
            ?>

            but Installer gave shorter code that works as well.

            i just needed to improve it a lil' bit cause i dont know why but script produces doublespace in output, and validator gives warning..

             <?=str_replace("  ", " ", date('r', strtotime($row['datums'])));?>

              Does the database system you're using have date/time formatting functions? It would probably be easier to use those.

                im using php/mysql and i dont know much about this db specifications. but anyway thanks for help.

                only one thing i dont get over and over is that with double space between Mon, and 13

                Mon, 13 Nov 2006 21:39:53 +0200

                  I don't see any double space. If your version of PHP has a buggy implementation of date('r') (as reported here, then you could always use the other formatting rules to construct an RFC2822 date yourself. Either in PHP or in your database query. Preferably the query, because then you don't need to convert from database date/time format -> date string -> integers -> unix timestamp -> date string.

                    Write a Reply...