Adding days to a Firebase time-stamp.

2,575 views
Skip to first unread message

kevin

unread,
Dec 7, 2014, 11:20:46 PM12/7/14
to fireba...@googlegroups.com

I am using the JavaScript API is it possible to add days to a Firebase time-stamp. 

Jacob Wenger

unread,
Dec 8, 2014, 12:44:42 AM12/8/14
to fireba...@googlegroups.com
Hey Kevin,

No, you cannot. The push IDs you are referring to are meant to be used as unique, chronologically sorted IDs, not timestamps. If you want timestamps, you'll have to store them yourself.

Jacob

On Sun, Dec 7, 2014 at 8:20 PM, kevin <kyou...@gmail.com> wrote:

I am using the JavaScript API is it possible to add days to a Firebase time-stamp. 

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/96d8705c-1bdc-4454-b4fd-36aa8b93ed86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kevin

unread,
Dec 8, 2014, 7:34:29 AM12/8/14
to fireba...@googlegroups.com


Thanks Jacob

What i am trying to figure out is Firebase timestamp is the same as this in javascript.

var time = new Date();
var newdate=Date(time.setDate(time.getDate()+12));
var cdate = new Date(newdate).getTime();

Please correct me if I am wrong.  Because I am trying to create a search that will search for the whole month in the database.

Jacob Wenger

unread,
Dec 8, 2014, 1:15:37 PM12/8/14
to fireba...@googlegroups.com
Hey Kevin,

It is not clear what you are referring to when you say "Firebase timestamp." I assumed your meant the push ID generated by calling ref.push().key(). As I said, those are meant to be used as unique, chronologically sorted IDs, not timestamps. Are you referring to those or to something else?

Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.

Rich D

unread,
Dec 8, 2014, 1:58:26 PM12/8/14
to fireba...@googlegroups.com
He may be referring to Firebase.ServerValue.TIMESTAMP

kevin

unread,
Dec 8, 2014, 2:05:38 PM12/8/14
to fireba...@googlegroups.com
Sorry for the confusion I was wondering if the Firebase Timestamp is similar as the JavaScript Date(); object?

With the following code below just using plain JavaScript.  I wanted to generate a Firebase timestamp if possible.


var time = new Date();
var newdate=Date(time.setDate(time.getDate()+12));
var cdate = new Date(newdate).getTime();



On Sunday, December 7, 2014 11:20:46 PM UTC-5, kevin wrote:

Jacob Wenger

unread,
Dec 11, 2014, 2:08:00 AM12/11/14
to fireba...@googlegroups.com
Hey Kevin,

I apologize for my confusion. Thanks for helping clear that up Rick!

Yes, Firebase.ServerValue.TIMESTAMP is very similar to new Date().getTime(). However, the value is generated on our servers, meaning that you can easily avoid differences in client's internal times. You can easily convert the value generated by Firebase.ServerValue.TIMESTAMP by storing it in a variable called timestamp and doing new Date(timestamp).getTime(). Then you can treat it like any other Date object.

Note that we also have a now variable in our Security Rules which you may find useful.

Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages