[SalesForce] How to get the server timestamp through SOQL query or REST API

This question was asked before, but the answer given was how to do it with Apex, and I am not using Apex:

How to get the current timestamp using SOQL query?

How do I do the equivalent of getServerTimestamp() in Apex, as either a SOQL query or through the REST API?

I need the server timestamp to record when I last do a sync with data that resides on Salesforce and my local database. I will then query for records that have a system modified timestamp later than the last sync. If I use my local timestamp, I risk and difference in clocks resulting in some modifications being missed.

Thanks for your help.

Best Answer

When trying to sync, you don't need to worry about the mechanics of determining the correct time to use. Instead, just use getUpdated (/vXX.X/sobjects/ObjectName/updated?start=X&end=Y in the REST API), which will return a list of ID values you can retrieve from and a value called lastDateCovered, which is the next start time that you should use in your replication. In flight requests won't be included, but the lastDateCovered attribute will be offset by any in flight requests-- your next sync request will automatically include any values you missed in the last request because they were still in flight (not fully committed). The only issue you have to worry about is selecting the correct first initial sync date/time. For more information, I'd suggest taking a look at the SOAP API Developer's Guide under Data Replication, and the Force.com REST API Developer's Guide for REST-specific considerations.