0

I have an app that posts to a firebase database. I am storing data such as the date created, id, description, etc. How can I figure the age of the posts in days using javascript?

Date Created:

$scope.products = [];
    firebase.database().ref('products').orderByChild('rank').startAt(0).endAt(10000).limitToLast(10).once('value', function(products) {

        products.forEach(function(product) {
          var product = {
            date: product.val().dateCreated,
            id: product.key,
            name: product.val().name

          };

returns Sun May 21 2017 00:12:13 GMT-0500 (CDT)

and current date:

$scope.date = Date();

returns Wed May 31 2017 11:12:06 GMT-0500 (CDT)

Given the above, I want to output 10 from the difference in the dates . How should I proceed?

Thanks in advance

MacD
  • 566
  • 3
  • 9
  • 27
  • 1
    You can use Date.prototype.getTime() on both and subtract afterwards. – xDreamCoding May 31 '17 at 17:20
  • 1
    Possible duplicate of [*How to calculate date difference in javascript*](https://stackoverflow.com/questions/7763327/how-to-calculate-date-difference-in-javascript). – RobG May 31 '17 at 20:43
  • 1
    @xDreamCoding - got it using getTime(). Thx.. – MacD May 31 '17 at 23:38

0 Answers0