Date operations (No API)

Hi everyone
It´s been a while since my last post in the community
I have a couple of questions regarding operations with dates (I didn´t find a solution on the community thad doesn´t use API´s)

I need to pick a date and do some maths with it and then show the results in other labels

Example: I selected 2021-10-21
Then:
Label 1: 2021-10-21 + 5= 2021-10-26
Label 2: 2021-10-26 (result of the previous operation) + 10= 2021-11-05

Of course ther is two “problems”. Wich blocks I need to use? How can I do the maths with months (Feb has 28 days, etc.)?

And my second question is… Is it possible to “translate” dates using block “date imput” into other lenguages? June → Junio (Spanish)

Thanks in advance

1 Like

Connect a Google sheet to your app and use the seconds since 1970 block and pass it to the sheet to convert to normal date and do all date operations.

3 Likes

I made a simple JavaScript code to get the date after certain number of days.
image
This is giving today’s date but if I add some days I get the future date in the label.
image

All managed by a web viewer extension running .html file added to the project as an asset…

The Google sheet solution is still a viable solution and it works just as good.

This is the blocks of the project

This is the JavaScript Code

<!DOCTYPE html>
<html>
<head>
<script src="https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js" type="text/javascript"></script>
</head>

<script>
  ThunkableWebviewerExtension.receiveMessage(function(message) {
    const dateObj = JSON.parse(message);
    const myDate = new Date(dateObj[0], dateObj[1] - 1, dateObj[2]);
    myDate.setDate(myDate.getDate() + dateObj[3]);
    ThunkableWebviewerExtension.postMessage(myDate);
});
</script>
</html>
2 Likes