+ Start a Discussion
dtaylordtaylor 

DateTime Issues

Hi,
Can anyone please tell me what is wrong with the piece of code?  I am trying to pull assets that have been updated since yesterday...
 

DateTime endTime = sfdc.getServerTimestamp().timestamp;

DateTime startTime = endTime.Subtract(new System.TimeSpan(1, 0, 0, 0, 0));

sforce.QueryResult qr = sfdc.query("Select Id from Asset Where SystemModstamp > " + startTime);

The error is:

System.Web.Services.Protocols.SoapException was unhandled
  Message="MALFORMED_QUERY: \nAsset Where SystemModstamp > 11/27/2006 8:59:45 PM\n                            

   ^\nERROR at Row:1:Column:47\nunexpected char: '/'"

SuperfellSuperfell
The default toString on dateTime does not use the ISO 8601 format required by SOQL. try XmlConvert.ToString(startDate) instead, you may also have to sort out some TZ corrections.
David GorslineDavid Gorsline
I have used the following.

Code:
"where SystemModstamp > " + myDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")

 This way, we're comparing apples to apples.
DevAngelDevAngel
I believe you can also use:

System.Xml.XmlConvert.ToString(new DateTime(), System.Xml.XmlDateTimeSerializationMode.Utc)