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
Ajith MDAjith MD 

Hello, I want to query createddate from any object and to save it in Datetime format. Can you please help me how to do it?

Dushyant SonwarDushyant Sonwar
CreatedDate datatype is already datetime.

If you want to format it in string example
Account acc = [Select id,createdDate from account limit 1];
DateTime myDateTime = acc.createdDate;
String formatted = myDateTime.formatGMT('dd/MM/yyyy HH:mm:ss');
system.debug(formatted);