Reputation: 1077
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))
}
})
Upvotes: 0
Views: 91
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