Get data every 3 months

The API I’m using only gives me historical data in less than 3 months.

In order for me to get all the historical data, I have to make several requests, every 3 months.

I thought about converting the current date and time to milliseconds and then subtracting the equivalent of 3 months for each request.

But I didn’t find an extension or method to convert that first.

Is there a better way to do this?

You can try your own way first.And for converting the time to melliseconds.Just use the get mellis block in the clock component.If you are wondering how to get the date and time as an instant so you can use them with this block, so you will find as well a block named make instant from parts.:+1:

Here the solution… sorry!

But is this the best way to do this?

Can you tell us how is this api works?Any what is your way exactly.you mean you will set the api to get data for a specific instant.Or you we will get data every 3 months? So we can help you better.Also have you tried your way?Does it work?

But does the API accept date as parameters for filtering historical dates? I did not understand.
From what you said, the API only returns the last 3 months, so I guess you can’t filter by date as this is done internally in the API.

Thank you!

Is this better than working with milliseconds?
Looking here, it is safer to do the calculation for milliseconds because I don’t have to worry about whether the day of the month exists or not, for example.

Here…

1 Like

Yes, but the interval has to be 3 months.
So I will make several requests to get a longer period.

nope.You can reread my post.I use another block which is make millis to convert this instant to mellis.

So there is no way.you can try to add them in a for loop so you can get them with the least amount of blocks :+1:And you can use makeMellis block to convert a normal instance ( you get from make instance from parts block ) to mellis.

1 Like

But friend, if the API doesn’t allow it, how will it do it?
Ok, Now , I saw API parameters. :+1:t2:

2 Likes

I’m working around an API limitation.
I will convert the current moment to milliseconds and then subtract 3 months from each request I make.
So I will take the history of the time I want back, making one request after another.

Now I don’t know exactly how I’m going to convert the date to LONG.
Any idea?

In app inventor ( and kodular as well ) a long isn’t different from an int ( in other languages they are.) So you can easily get data without converting any thing at all.:wink:

2 Likes

This should be simple, but I don’t remember how to do it.

Do you mean the way of getting the data 3 monthes by 3 monthes.I can make it with this way.
for each number from 90 to ( the number of days you want the counter to stop on for example 182 (that means that we will get the data of the last 6 months 3 by 3) by 90
you will now form your request.In the start days parameter set it to number - 90 and the end day to the number.that’s it! now get data from the api with this url you have.

You don’t know how to do what? Do the transformation in Long or use the API?

1 Like

Sorry for the confusion.
I was thinking of converting the dates in LONG to pass as a parameter …

But it must be simpler than I think …
The LONG of the parameter must be the number of days.

I will test and return here.

Thank you guys!

You can try this way as well:

1 Like

All the details of your question have been answered above. Now is the time for you to try.

1 Like

Thank you guys.

But I will have to do the math in milliseconds, because that’s how the api works.
I will use the Get Millis block of the Clock component for this and make an account to subtract 3 corresponding months in milliseconds.

1 Like