XML dateTime and PHP

Today I had to grapple with a Sage based web service and I discovered that XML dateTime formats can give you a large headache

Foolishly I thought that being a format called dateTime, i could simply pass the webservice a standard PHP date string 19/7/2011 10:05:55 generated by the php date function

date('d/m/Y H:i:s');

But the date would not appear on the receiving end of the web service, the data was simply being invalidated every time. This is due to the fact that the xsd:dateTime (XML scheme definition) format is a ISO8601 formatted type, and is a concatenation of xsd:date and xsd:time. The overall format of the date comes out like 2011-07-11T13:20:00+01:00, with T being the concatenation and the +1:00 being the UTC timezone offset. Nicely enough PHP can generate this type of timestamp with our friend the date function, simply run:

date('c');

Wasn’t too difficult was it :p

About these ads

4 Responses to XML dateTime and PHP

  1. renga says:

    Hi Dan Richards,

    Thanks for solutions. Its really helped me to solve the date time issue with php and xml

  2. fidr says:

    nice solutions…..thankyou so much :)

  3. Tito says:

    You save my day … thanks !!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: