Trying to build a streak daily counter in my app. these are my blocks but they are not working

my daily counter app premise is 2 blocks one in screen1 that checks if the app is used for the first time if so stores the time tag, then the second block measures the duration between that time the app is first used and now.

Untitled (Recovered).bmp (1.7 MB)

Untitled2

Read the error message.

It can’t find your tag in TinyDb, so it reads by default what you wrote in your “value if no tag there”. So it can’t laucnh a clock duration block with your first date that is “error”.

As ontstudio said, look at the error
It said “the Duration (block) cannot accept Error and May 23, 2020”
That’s mean it returned value is not There string.
Have you checked if you saved any thing in tinyDB in the tag of isitfirsttime?
If you didn’t, this error would occur in your case.

1 Like

thanks i fixed the initial error but now i get this error

The problem is that the duration is calculated between instants.

May 23, 2020 it´s not an instant.

Maybe you can try to create an instant from a certain date.

image

now i am having this error argument to MakeInstant should have form MM/dd/YYYY hh:mm:ss, or MM/dd/YYYY or hh:mm
Note: You will not see another error reported for 5 seconds.

That’s because you’re not putting the date format right

If you use any of these methods, it’ll work for you:

image

Here’s the result. The Label 1 and the Label 2 with their instant:

image

But then i can not calculate the duration between the 2 instant in that form

I used the format date time block in MM/dd/yyyy hh:mm:ss and i still got the error that it can’t accept the argument of the date in this form.

Ofc this happen. You make the instant of it.
Why not just use Format Date Time

But the “Now” block is an instant. There’s no need to format it that way. You’re making an instant of an instant… it has no sense…

And in the second label you are using clock2 and getting the instant from clock1

1 Like

I think there’s nothing wrong with this, but this is the point

try this

blocks (72)

I made this app to test-simplify the duration tool before using it in my app. I tried using the format date first but i got this error message, hence why i tried the instant tool. the duration tool seems to refuse to work with every form i try.

"


Can you tell me what are trying to obtain?
The duration from when to when?

Clock component: Duration
From the Kodular documentation, we can see that you’ll need an instant, but you have used the format date (which will return a string, not an instant)

Therefore, if you want to use the text block, you’ll need to use make instant
Clock component: Make Instant
Only the string in MM/dd/YYYY hh:mm:ss or MM/dd/YYYY or hh:mm is accepted.

Try this, this must work. I found that no matter u use format date time or format date it’s fine
Label 3 should be 0, because the duration is from now to now

If you want to make some modifications, for example you already have the string/text with the format of MM/dd/YYYY hh:mm:ss or MM/dd/YYYY or hh:mm, you may do this.


It will return 2905063000

1 Like

I had the same idea some time ago and posted it in the AI2 forum:

https://groups.google.com/forum/#!searchin/mitappinventortest/statistic|sort:date/mitappinventortest/Md9uNzxJh3g/xzHS3CGJBQAJ

The same request here to experienced extension developers at Kodular:

I’m still waiting …

But try this, what I aleady have done some time ago:

grafik

3 Likes

Since we are storing the value in tinyDB as Millis, then do we need to do Clock1.Get Millis ‘instant’ on tinyDb1.Get Value.

Shouldn’t it be tinyDB.Get Value directly on the Clock1.Duration end socket ?

:thinking:

You are actually right! I think is a minor mistake of @dora_paz