I am picking up a date/Time from an xml file. I have no control over the format of the xml file.

One of the variables is date/time in the format 2009-12-09T14:32:47+00:00

I have tried changing this into a more manageable date format for storing into a MySQL db but I am having no luck.

Does anybody know a way to convert this into 2 seperate variables. One for date (Y-m-d) and one for Time (H:i:s)

Thank you.

    [man]date[/man] and [man]strtotime[/man], though I'm surprised if MySQL can't parse ISO standard timestamps for itself.

      Thanks for the responses but I have already tried Date before posting.
      I tried Date using

      $TS = "2009-12-09T14:32:47+00:00";
      echo Date("d/m/Y",$TS);

      and got
      Notice: A non well formed numeric value encountered in C:\fi\dt.php on line 2
      01/01/1970

      I have tried other variations but could not get a proper date.

      I looked at the MySQL link but this does not help, I would like 2 separate date/time variables to be produced from the original date entry before insertion into the db so I can work with the dates elsewhere in the app.

      ie. Date = 2009-12-09 and Time 14:32:47

      I have also tried using substr($TS, 0, 10); to get the date but this is not always going to be accurate if say the leading zeros are not present and I could then get a string of 2009-12-9T which of course would fail being a date.

      I was hoping that there would be a date function I could just chuck the $TS at and get out separate date and separate time.

        I have also just tried submitting the $TS variable straight to Mysql with the field configured as a Date/Time and got this response
        You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'On,6,2009-12-09T14:32:47+00:00' at line 1

          Still, have a look at the page I linked to. It's not for date, it's for date_format.

            Pigmaster wrote:

            You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'On,6,2009-12-09T14:32:47+00:00' at line 1

            So you didn't quote the string in the query, did you? MySQL is telling you you've got a syntax error; if the problem was that its date parser didn't recognise the format the error message would have been different.

              For doing it with PHP code, you should reread Weedpacket's first post.

                Sorry but I have tried many things but just do not understand it fully, so I am having to go with the substr method I stated before and just hope that the output will always have the leading zero's in place thus always have the same number of characters in the $TS
                Thank you for you help.

                  The date() function expects a timestamp, not a date string. Try:

                  $TS = strtotime("2009-12-09T14:32:47+00:00");
                  echo date("d/m/Y",$TS);
                  

                    Did you ever read and try MySQL's date_format function?

                    date_format(SOME_DATE, '%Y-%m-%d');
                    date_format(SOME_DATE, '%H:%i:%s');

                      Write a Reply...