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
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

Regards,
Nandika
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,

Cheers,

Dhriti
 
JyothsnaJyothsna (Salesforce Developers) 
Hi,

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();

system.debug(myDateTime);


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

Let me know if you need any help!

Best regards,
Jyothsna
Nandika Kodituwakku 10Nandika Kodituwakku 10
Hi,

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?

Regards,
Nandika