I’m working with the wordpress XMLRPC to post some future posts to my blog, but I’m running into some issues with date formatting… basically got myself all discombobulated 🙂
So I’ve set up the “future” post date. It’s just fine.
$thetime = date("Y-m-d H:i:s", strtotime("+ $number days", strtotime(date("Y-m-d H:i:s"))));
($thetime echos out the date i’m shooting for – so all is well here)
But the wp client wants the date in ISO.8601 format. So I changed it this way:
$content['date_created'] = date( 'c', strtotime($thetime) );
But I’m getting a response from the xml-rpc client that it’s malformed.
So how would you go about changing $thetime to iso.8601 format since I thought that’s what ‘c’ does? Am I doing something wrong?
First, verify the outputted string and make sure that the output is what you expect. There may be a completely unrelated bug (for example a forgotten debugging
echo
) in there.Some implementations may require the date to be in UTC time. Simply use
gmdate
instead ofdate
, and add aZ
at the end:According to XMLRPC specifications, datetime is defined in this tag
<dateTime.iso8601>
and has this format 19980717T14:08:55. So the complete tag looks like this
<dateTime.iso8601>20090322T23:43:03</dateTime.iso8601>
This is the common mistake when using php
xmlrpc_encode_request()
function, which does not automatically convert date. Rather usexmlrpc_set_type()
function.The above example will output something similar to: