Statistics using date in Firbase

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

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:

// 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)
2 Likes

Sorry i was extremely unclear - DDATE was an typo… :smiley:
image

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 ?

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.

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

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).

1 Like

Hmm…
Difficult - I do not understand how i can change the VARIABLE
to a date…?
image
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

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

to create your cloud variable:

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

1 Like