Hello,
Right now i am getting the date via an rss feed so the date looks like:
Wed, 26 Nov 2008 06:47:52 -0800

I want the date to look like 11/26/2008 i dont even want/care about time and the -0800 part.

What would be the best/most efficient way to convert it?

Thanks alot! :xbones: :evilgrin:

    Probably easiest to use [man]strtotime/man to parse the date into a Unix timestamp which you could then use in conjunction with the [man]date/man command to display the timestamp in whichever format you prefer.

      3 months later

      I think something like this will work. I use it when I need to format dates.

      $datevariable = date(); // whatever you have your date variable stored to
      
      $stringArray = explode("-", $datevariable);
      $date = mktime(0,0,0,$stringArray[1],$stringArray[2],$stringArray[0]);
      $convertedDate = date("F j, Y", $date);

      This takes a date from a MySQL DB: 2009-01-01 00:00:00

      And formats the date to display: January 1, 2009

      You can format how you want by inserting the dd mm and yyyy variables for the F j, Y part.

        As b.g. said:

        echo date('m/d/Y', strtotime($rss_date));
        
        // echos: 11/26/2008

          As I said approximately 3 months ago, you mean? :p

          EDIT: Also, if the date is coming from a DB, then there's nothing you need to do in PHP at all; just use your DBMS' date formatting function (e.g. MySQL's DATE_FORMAT() function).

            More like 2 & 2/3 months. Don't exaggerate.

            Edit: Oops. I guess you did say "approximately".

              Write a Reply...