Support » Fixing WordPress » XMLRPC, how to work with returned datetime value?

  • The Codex defines the post_date value returned from a wp.getPost as a “datetime.” I’m unable to print that value directly, as that results in error:

    The website encountered an unexpected error. Please try again later.

    I tried using Date() such as

    $string = Date("Y/m", datetime_value)

    but just get an empty string. I’ve done a lot of searching on this and I can’t locate any definitive posts on how you extract values like month and year from this particular returned data type and make them strings.

    Can someone please explain how to turn this data type into useful values?

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thanks, but I when I try to use that function I get:

    Fatal error: Call to undefined function mysql2date() in /home2/spinland/public_html/drupal7/modules/php/php.module(80) : eval()’d code on line 35

    Okay, so looking into the code, that function appears to be in the WordPress includes folder. The problem is, this is not a WordPress site I’m pulling the posts into–that’s why I’m using xmlrpc in the first place. WordPress-specific code is not available.

    So, is there a function (or functions) that can process this datetime data type that exist in the standard PHP libraries?

    Thanks in advance!

    Some progress, but a new problem. Through more searching I found this bit of code that works better in that it doesn’t crash the web page or return an empty string:

    $datetime = strtotime($post['post_date']);
               $mysqldate = date("Y-m-d H:i:s", $datetime);

    The issue now is I pull several posts from the blog with wp.getPosts and in every case the final $mysqldate string from the above code resolves to:

    1969-12-31 19:00:00

    Either $post[‘post_date’] is not being returned in the xmlrpc call, or something in how I’m trying to format the data to be useful is not working. I’m successfully pulling other data out of the blog, like link and title and content, so I know the basic xmlrpc operations I’m doing are sound.

    Does anyone have any ideas?

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘XMLRPC, how to work with returned datetime value?’ is closed to new replies.