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
Doyeli Ray 5Doyeli Ray 5 

I need to use Today's date in a format like 2016-03-22T03:44:34.000-07:00 in a where clause in a query. Can you please help how to format this

I need to use Today's date in a format like 2016-03-22T03:44:34.000-07:00 in a where clause in a query. Can you please help how to format this.
like 

SELECT id,name,SubscriptionId,createdDate FROM Amendment where createdDate = today

and today needs to be in this format, e.g.
2016-03-22T03:44:34.000-07:00

So, if I get system.today(); I need your help how to format that as I mentioned above.

Thank you
Aslam ChaudharyAslam Chaudhary
system.now().format('yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX');

 
Prashant Pandey07Prashant Pandey07
You can format your date in the string and then you can query the record..The code will be something like this.
 
String dateFormat = 'yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX';
DateTime dt = DateTime.now();
String dateString = dt.format(dateFormat);

Strring strQuery = 'select id from ';      

strQuery = strQuery + 'Amendment where  CreatedDate = '+dateString +'  order by createdDate desc';

Mark this as the best answer to help the community grow.
Thanks,
Prashant