Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change data type from String to Date

I'm getting in trouble where I was coding for connection using OpenX API with XML-RPC2. I get the problem that the data type is required by the fire function is the dateTime.iso8601.

This is my code:

$sdatetime = new DateTime('2013-01-01 00:00:00');
$edatetime = new DateTime('2013-06-01 00:00:00');

$startDate = $sdatetime->format(DateTime::ISO8601);
$endDate = $edatetime->format(DateTime::ISO8601);

try {
    $result = $aClient->agencyPublisherStatistics($sessionId, 1, $startDate, $endDate);
    print_r($result);
} catch (XML_RPC2_FaultException $e) {
    die('Exception #' . $e->getFaultCode() . ' : ' . $e->getFaultString());
}

This is result error, when I run script above:

Exception #3 : Incorrect parameters passed to method: Wanted dateTime.iso8601, got string at param 3

If I run print_r(gettype($startDate)); I get the type data is string not date.

My question, for variables $startDate and $endDate how to make their data type to be dateTime.iso8601 or date rather than string.

Thanks.

like image 765
Loren Ramly Avatar asked Nov 02 '22 22:11

Loren Ramly


2 Answers

it looks like your agencyPublisherStatistics requires specific XML_RPC2_Value date object. You cancreate this by using.

$startDate = XML_RPC2_Value::createFromNative($startDate, ‘datetime’);

same for the end date.. let me know if this works..

like image 161
Dinesh Avatar answered Nov 09 '22 11:11

Dinesh


Try this,

$sdatetime = date(DATE_ISO8601, strtotime('2013-01-01 00:00:00'));
$edatetime = date(DATE_ISO8601, strtotime('2013-06-01 00:00:00')); 

OR

Check below links,

http://pear.php.net/manual/en/package.webservices.xml-rpc2.client.php

https://bugs.php.net/bug.php?id=51950

may this help you.

like image 23
Tony Stark Avatar answered Nov 09 '22 12:11

Tony Stark