- Home /
Question by
danieilng21 · Mar 04, 2019 at 01:01 PM ·
c#querytimestamp
Firebase query based on Timestamp
I would like to create a query of database filter by timestamp - e.g. From start at 365 days ago and end at Now. How to convert regular date to firebase timestamp format (UNIX Epoch?) for the query?
Comment
Best Answer
Answer by Ymrasu · Mar 04, 2019 at 03:07 PM
using System;
has a DateTimeOffset class that can convert to and from unix time in milliseconds. Here is an example of Now and 365 days ago converted to milliseconds since 01/01/1970:
var now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
var lastyear = DateTimeOffset.Now.Subtract(new TimeSpan(365, 0, 0, 0)).ToUnixTimeMilliseconds();
I had done it by getting the current servertime of firebase, and substrate it with milliseconds equivalent to 365 days. Thanks anyway.