Bright
Bright

Reputation: 1077

Save timestamp to firesote using cloud functions

How do I save a timestamp value to firestore using cloud functions.

I tried this (adding 30 days to the timestamp) but it ends up saving the value as a number

var now = new Date();

   await docRef.update({
       'subscription':{
          package:req.query.package,
          endDate: now.setTime(now.getTime()+(30 *24+60+60+1000))
        }
     })



firestore

Upvotes: 0

Views: 91

Answers (1)

Marc Anthony B
Marc Anthony B

Reputation: 4099

If you want to add days to the date, then you should setDate() instead. By using setTime() you're setting the time instead of the date. See code below:

var now = new Date();
now.setDate(now.getDate() + 30);

   await docRef.update({
       'subscription':{
          package: req.query.package,
          endDate: now
        }
     })

For more information, you should check out this documentations:

Upvotes: 1

Related Questions