Search code examples
firebasegoogle-cloud-platformfirebase-realtime-databasefirebase-security

Can you parse a Date in the FB Security Rules?


I have a string datetime in my Realtime Database. In the security rules I would like to check if this date is > now:

".write": "data.myStringDate.val() > now"

Since now is in milliseconds, I need to convert my string to milliseconds as well:

".write": "Date.parse(data.myStringDate.val()) > now"

But Date.parse() doesn't seem to work in Firebase: it returns Unknown variable 'Date'.


Solution

  • As far as I know it isn't possible to reliably parse a string to a timestamp in Firebase Realtime Database security rules. If you need the value as a timestamp, consider (also) storing it as a timestamp.