# Statistics using date in Firbase

**URL:** <https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047>\
**Category:** Questions about Thunkable X\
**Created:** [March 8, 2023, 2:46pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047 "2023-03-08T14:46:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefansladdeneng1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/stefansladdeneng1/32/170123_2.png) [@stefansladdeneng1](https://community.thunkable.com/u/stefansladdeneng1)\
**Post date:** [March 8, 2023, 2:46pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/1 "2023-03-08T14:46:54Z")

</div>

Hi,  
how can i achieve DDate:Statistics in Thunkable via using Cloud Parameter?

Say i would like to have the following in firebase.  
Datestats: “09, Mar23”; “ **145** ”  
“08, Mar23”,“ **99** ”

It seems like impossible to figure out how to do this a proper way…  
i have triev a lot different versions but without success…  
Anyon knows a successful way?

Thanks  
Stefan

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 8, 2023, 3:36pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/2 "2023-03-08T15:36:31Z")

</div>

> [@stefansladdeneng1](#):
>
> DDate:Statistics

Is DDate:Statistics a specific format for information? What do the 145 and 99 represent? It’s certainly possible to generate a text string like “09, Mar 23” for the current date. What blocks have you tried?

I would typically generate custom date/time text strings using Javascript (Google it or ChatGPT can provide the code). But you don’t have to do it that way. Here is ChatGPT’s response:

```auto
// create a new Date object with the current date and time
const currentDate = new Date();

// create an array of month names to use in the output
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

// extract the month and day from the date object
const month = months[currentDate.getMonth()];
const day = currentDate.getDate().toString().padStart(2, '0');

// concatenate the month abbreviation and formatted day into the final output string
const formattedDate = `${day}, ${month}${currentDate.getFullYear().toString().slice(-2)}`;

console.log(formattedDate); // output: "08, Mar23" (assuming current date is March 8th, 2023)

```

---

<div class="post-metadata">

**Author:** ![stefansladdeneng1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/stefansladdeneng1/32/170123_2.png) [@stefansladdeneng1](https://community.thunkable.com/u/stefansladdeneng1)\
**Post date:** [March 9, 2023, 7:30am UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/3 "2023-03-09T07:30:29Z")

</div>

Sorry i was extremely unclear - DDATE was an typo… 😃  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/2/f22ae1e0395479c52f0cf46037dd53dc05eee962.png)

Look at the image: This is stats on how many time the app has started.  
This is generic and the number rise by one each time the app is “started/opened”

What i want is;  
“The app was starting X many times on this particular date” and store it per date - and when a new date start over with 0 n the beginning

Any clearer ?

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 9, 2023, 8:04am UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/4 "2023-03-09T08:04:08Z")

</div>

Yes. The algorithm for that would be:

When screen opens  
…If currentDate \> lastOpenedDate  
…Set lastOpenedDate to currentDate  
…Set cloud variable /08Mar23/firstpagestarts to cloud variable /08Mar23/firstpagestarts + 1

And you would need a function to convert currentDate into “08Mar23” format using Javascript or Text blocks in Thunkable.

---

<div class="post-metadata">

**Author:** ![stefansladdeneng1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/stefansladdeneng1/32/170123_2.png) [@stefansladdeneng1](https://community.thunkable.com/u/stefansladdeneng1)\
**Post date:** [March 9, 2023, 8:42am UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/5 "2023-03-09T08:42:10Z")

</div>

Great - i will try this one and let you know  
(I think i wasvery close to this earlier but di not get it to work…)  
I’ll let you know…  
Cheers

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 9, 2023, 3:38pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/6 "2023-03-09T15:38:54Z")

</div>

Just one change… you can compare currentDate to lastOpenedDate and if they are **not equal** , then continue. You don’t actually need to know if currentDate is greater than lastOpenedDate because any current date that isn’t the same as the last date the app was opened will automatically be greater (newer).

---

<div class="post-metadata">

**Author:** ![stefansladdeneng1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/stefansladdeneng1/32/170123_2.png) [@stefansladdeneng1](https://community.thunkable.com/u/stefansladdeneng1)\
**Post date:** [March 11, 2023, 1:45pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/7 "2023-03-11T13:45:57Z")

</div>

Hmm…  
Difficult - I do not understand how i can change the VARIABLE  
to a date…?  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/0/706173283ca38be16b24d113a8923c3c61e4c020.png)  
If i do this i only get datestat:date  
When it should be  
Datestat11Mar2023:145 (WHere 145 is the actual statistic)  
Any idea - if so pleasse create some blocks for my understanding…  
Thanks

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [March 11, 2023, 5:35pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/8 "2023-03-11T17:35:32Z")

</div>

You have to use the dynamic variable blocks at the bottom of the Variables drawer:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/d/5d2181523d3690de7c811f47dd3ac7342260f74c.png)

to create your cloud variable:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/f/4f7efe56106866e2c1e3d98fdcb37f117de9db3c.png)

You can also use variables and paths together in the text field:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/3/d323b65c01dd5edf06a91df8cac9a2c7df584885.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [June 9, 2023, 5:36pm UTC](https://community.thunkable.com/t/statistics-using-date-in-firbase/2314047/9 "2023-06-09T17:36:12Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
