You need to sign in to do that
Don't have an account?
DateTime - System.TypeException: Invalid date/time: 2010-02-25T09:50:30Z
I need the currentTime as a DateTime object to use it my SOQL like :
m.End_Time__c < :currentTime
where End_Time__c is of type "DateTime".
Here is the relevant piece of code
public Datetime getCurrentDateTime() {
return DateTime.valueOf(System.now().format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
}
testmethod static void test() {
ApexPages.StandardController controller = new ApexPages.StandardController(new My_Custom_Object__c());
MyController mc = new MyController(controller);
System.debug('>>>>>>>>>>>>>>>> ' + mc.getCurrentDateTime());
}
When I run the test, I get the following exception :
System.TypeException: Invalid date/time: 2010-02-25T09:50:30Z in the line highlighted red
What is wrong with the date format? Looks ok to me...
Thanks a bunch..
In apex, you can just bind it directly, e.g.
DateTime dt = System.now();
[select someField__c from somewhere__c where myField__c > :dt];
All Answers
Thanks for your replies.
How will I use it in my SOQL?
Select m.Start_Time__c From My_Obj__c mWHERE m.Start_Time__c > 2010-02-25 18:34:09
System.now() returns "2010-02-25 18:34:09" and SOQL doesn't like it. It complains it is a MALFORMED QUERY.
Start_Time__c is of the type 'DateTime'
Thanks
Here is how data is stored:
Start_Time__c
2010-02-25T02:01:00.000Z
In apex, you can just bind it directly, e.g.
DateTime dt = System.now();
[select someField__c from somewhere__c where myField__c > :dt];