datetime datatype not working in soap php

This is my code

$c = new soapclient('', array('authentication' => array('LoginID' => 'x','Password'=>'x'))); $timezone = new DateTimeZone('UTC'); $time='2012-04-17T16:50:45'; $date = new DateTime($time,$timezone); $sourceid=array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' =>$date); $stockprice = $c->GetAvailableRoutes($sourceid); print_r($stockprint);

it's not working in datetime format datatype variable

it shows error like this

Fatal error: Uncaught SoapFault exception: [soap:Client] Server was unable to read request. ---> There is an error in XML document (2, 252). ---> The string '' is not a valid AllXsd value. in E:\xampplite\htdocs\index1.php:9 Stack trace: #0 [internal function]: SoapClient->__call('GetAvailableRou...', Array) #1 E:\xampplite\htdocs\index1.php(9): SoapClient->GetAvailableRoutes(Array) #2 {main} thrown in E:\xampplite\htdocs\index1.php on line 9


You need to format it, otherwise you are throwing an DateTime object into your array (which PHP tries to convert to a string, which does not work)

For example:

$date->format('Y.m.d H:i:s');


$sourceid = array('SourceID'=>'244','DestinationID'=>'477','DateOfJourney' => $date->format('Y.m.d H:i:s'));


I had a similar problem when using a SOAP service from PHP. I fixed it using:


(ISO 8601 date, added in PHP 5, looks like: 2004-02-12T15:19:21+00:00)

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:datetime datatype not working in soap php