Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
do maths with firebase timestamp

I am saving the Firebase server timestamp using serverTimestamp() in version 9. And then I need to do some maths, for example adding 3000ms. However it seems that serverTimestamp() reurns an object and therfore simply adding 3000 is impossible. So far I have dealt with this saving the timestamp in my database and then reading it. This way it works but it involves an extra read and write operation in the database just to get this value on JS.
Is there a way to transform the serverTimestamp object to a number directly on JS without involving writing and reading from the database?


code not working (cannot sum 3000 to an object):

var NewserverTime = serverTimestamp() + 3000;

Code working but the extra step of reading and writing in the databese seems not very elegant...

 set(ref(db, "/dabasepath"), {
    ServerTime: serverTimestamp()   
});

const firebaseRef = ref(db, "/databasepath");
onValue(firebaseRef, (snapshot) => {
          NewServerTime = snapshot.val() + 3000;  
 });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no way to store-and-transform a server-side timestamp with a single write operation. To determine the server-side timestamp you'll always have to write-then-read it.

My common approach is to store the timestamp and the offset as separate fields, and then checking both fields in the query, or having a calculated "timestamp plus offset" field that is automatically updated from Cloud Functions (which causes only an extra write).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!