+ Start a Discussion
Nandika Kodituwakku 10Nandika Kodituwakku 10 

How to get the sysdatetime()

Hi Devs,

How do I get the sysdatetime() from salesforce db like SQL server as below?

select convert(varchar(26), sysdatetime(), 21) as CET

Dhriti Moulick 16Dhriti Moulick 16
Salesforce contains follows 2 ways to identify your locale:

1st way:
1.Click on Setup --> company information --> Default Time Zone

2nd Way:

1.Click on setup --> user --> click on any users --> In Locale Setting section --> Check Time Zone.

Now based on current login user, record will getting created in SF.

for example, after creating record in Lead object,you can consider Lead object as DB Table and CreatedDate or ModfiedDate as DB Cloumn Name.

you can check the createdDate and ModfiedDate of that particular Record using following SOQL query:

[SELECT CreatedDate from Lead];
You will get the date and cross check with the locale in which the user resides.

Please let me know if you have any concern,


JyothsnaJyothsna (Salesforce Developers) 

Please try this below code in the anonymous block(go to Developer Console--->Debug--->Open execute anonymous window).You don't need to use SOQL. You can just create a new DateTime and set it to the current date and time like below
DateTime myDateTime = system.now();


Once execute the above code then go to log files check the output.

Let me know if you need any help!

Best regards,
Nandika Kodituwakku 10Nandika Kodituwakku 10

Thank you all for the quick response.
Actually my requirement is bit different, I'm using the DataStage connector to connect SF to extract data and load to our data warehouse.

Existing framework using the sysdatetime (SQL server) function to get the Database date and time. So same way  is there a way to get SF database system date and time using the SOQL?