You need to sign in to do that
Don't have an account?
Davser
DateTime.Format Issue
Hey,
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:
myDateTime.format('yyyy-MM-ddTHH:mm:ssZ');
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
You need to explicitly quote the T and Z, or you'll get an error.
Example:
system.debug(system.now().format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
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.