Fargho
Fargho

Reputation: 1277

Save and restore date to firebase?

i have a small problem with firebase and angular 2.

I try to save a user into the firebase database. Everythings works good, but the date isnt stored.

let now: Date = new Date();
let premiumExpireDate: Date = new Date();
premiumExpireDate.setDate(premiumExpireDate.getDate()+14);

// Insert data on our database using AngularFire.
this.angularfire.database.object('/accounts/' + userId).set({
    name: name, // works well
    dateUpdated: now, // isnt stored
    premiumExpireDate: premiumExpireDate // isnt stored too
}).then(() => {
    ...
});

Do you have a idea, how to save and also restore a data to and from firebase?

Thanks a lot!

Upvotes: 2

Views: 2162

Answers (1)

Mathew Berg
Mathew Berg

Reputation: 28750

You can't save a date object. You'll have to convert it to timestamp

this.angularfire.database.object('/accounts/' + userId).set({
    name: name, // works well
    dateUpdated: now.getTime(), // isnt stored
    premiumExpireDate: premiumExpireDate.getTime() // isnt stored too
}).then(() => {
    ...
});

Upvotes: 5

Related Questions