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.Format Issue


I'm trying to use the DateTime.format()method to create a SOQL query string. The string needs to be dynamic, so am literally creating a String for my query. Obviously I'd like to be able to say:





However this gives me an error saying : "Unrecognized format: yyyy-MM-ddTHH:mm:ssZ".


Am I missing something really obvious here, how else should I be formatting a datetime for a soql query?


Any ideas are greatly appreciated!

David Walshe




Best Answer chosen by Admin (Salesforce Developers) 

You need to explicitly quote the T and Z, or you'll get an error.






Edit: Also remember, if you do use a function that returns the current time zone instead of GMT, to pass the datetime through DateTime.valueOfGmt() first.

Message Edited by sfdcfox on 11-10-2009 03:18 AM