function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

DateTime Issues

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: '/'"

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.

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

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

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