datetime datatype not working in soap php

This is my code

$c = new soapclient('http://www.redbus.in/WS2/BookingService.asmx?wsdl', 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)


  • OOP Java: Creating a stock inventory program
  • value change listener invoked for all dropdowns instead of only the current
  • Linear Regression analysis for Date column in SQL Server
  • Node Async - Callback was already called - using 2 for loops and an if statement
  • Cannot select multiple items in a dropdownlist
  • str_getcsv not parsing the data correctly
  • How to sort an array considering localization?
  • Store array in cookie
  • Cookie multiple values
  • Azure Media Services Shared Access Policy limitations
  • NHibernate: Persist an object with children
  • Populating a DropDownList with text and values
  • Saving from a view model to a model in ASP.NET MVC
  • ColdFusion - DateTime Format with GMT offset
  • Convert Python date to Unix timestamp
  • Recursive regex not matching template blocks
  • Matlab, plotyy, datetime, and DatetimeTickFormat
  • Mysql UPDATE ON DUPLICATE KEY only inserting
  • LINQ to NHibernate WHERE EXISTS IN
  • How do I make WIF use RSA15 when encrypting data using a certificate?
  • How to use java.time.LocalDate on a Play Framework JSON Rest?
  • Converting Twitter DateTime to Localtime with adding UTC offset [duplicate]
  • How to parse utc date
  • What's the alternative to IValueFormatter in AutoMapper?
  • Running sp_executesql query expects parameter @statement
  • How to get ID of changed file on Google Drive
  • How to set infinite shared access signature policy in azure?
  • Entire JSON into One SQLite Field with Python
  • stop execution in Custom validator if it false
  • Add dynamic data to line chart from mysql database with highcharts
  • Extract zip entries to another Zip file
  • ActiveRecord query for a count of new users by day
  • Illegal mix of collations for operation for date/time comparison
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Matrix multiplication with MKL
  • Hits per day in Google Big Query
  • File not found error Google Drive API
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Converting MP3 duration time
  • How can I use threading to 'tick' a timer to be accessed by other threads?