Calcolare i giorni tra la data di scadenza e la data odierna

Ah yes , sorry :joy: :man_facepalming:t2:
You have two ways

  1. When initialize,before set the calculation you have to get value from list picker and then set the math block.
  2. You can retrieve expiration data from tinyDb but you have to save it the first time , after saving in tinyDb all the time you start app you will get the expiration date

Mi spiego meglio. Quando parte l'app deve avere già salvato questo dato altrimenti bisogna fornirlo. Hai due possibilità

  1. Quando carica lo screen prima selezioni la data e poi imposti il calcolo
  2. La prima volta salvi la data di scadenza nel tinyDb ed a ogni ingresso valuti se c'è il valore nel tinyDb e lo prelevi per il calcolo .

Obviously, by first selecting the expiration date and then the calculation; everything is great. If instead I save the calculation in the TinyDB; even if I run the app the following day; it tells me that the remaining days are the same as the day before, since it can't run in the background.

You have to set the get value from TinyDb as first block. Save it in a variable or set directly in the label and then starts the calculation

The calculation is always performed every time I go to indicate the expiry date; otherwise the same days remain..since it doesn't work in the background. I hope they can integrate into Mit App Inventor one day; the possibility that the apps can also work in the background. @Taifun has already taken a first step in this direction..with his extension "Taifun Alarm Manger".
Happy Sunday

Nicola

If you save the expiration day in the tinyDb you will find it when open the screen. The only thing that doesn't work is a notification when app is closed. Background task works only with some extension

If the app is in the background, there is no need to calculate the remaining days... nobody will be able to read it anyway...

Therefore after opening the app again, them do the calculation using the stored expiration date from TinyDB

duration = expiration date - current date

Taifun

I fully agree with you, if every time I open the app; I have to calculate a different expiration date. Instead the expiry date is always the same (e.g. 20 days left)..so if I open the app after two days; he will have to tell me that there are 18 more days to go.

If you save 30/03/2023 as expiration day when you open the app in 20/03/2023 it will show you 10 days to go. If you open the app in 25/03/2023 it will show 5 days to go. With some extra code in 5/04/2023 you will also show : it's 5 days after expiration day and so on

Exact

You have to use TinyDb. The first time you set the value and then everyday you open app countdown appears.
In your code ,when screen initialize first block has to be TinyDb get value . Set it in a variable and use it for the calculation

1 Like

Buongiorno,
non riesco a trovare il modo per sottrarre i giorni dalla variabile..

Hai cambiato totalmente la logica ? Come consiglio prova a scrivere i vari passaggi che ti servono e poi lo traduci in codice.
Controlla bene che hai due variabili con nomi simili rimanenti e restanti .
Controlla sempre il tipo di dati , non puoi sottrarre date ma il loro corrispettivo in millisecondi, le operazioni matematiche possono essere fatte solo tra numeri e non altri formati.
Il vecchio codice era finito, dovevi solo anticipare la chiamata al tinyDb

L'avevo anticipata la chiamata al TinyDB; ma la scadenza caricata corrisponde sempre agli stessi giorni. Se a te non ti dispiace, ti mando direttamente il file AIA; e così potrai vedere tutte le operazioni

Aia file removed

Sono da mobile .
Non vedo le immagini con il codice anticipato

In giorni rimanenti immagino ci sia un numero , tipo 20 o 10. Nel tiny invece devi salvare la data di scadenza e dopo usarla come serve, così la prima volta usi il date picker per selezionare la data di scadenza e la salvi nel tiny così quando ti serve è lì.
Apri l'app recuperi da la data di scadenza e la usi per il calcolo, per visualizzarla o quello che ti serve . Naturalmente cambiando il formato a seconda dell'uso .

Edit Usa direttamente l'instant del data picker e i vari blocchi format per modificare la visualizzazione

Io partirei così:

  1. chiamo il tinyDb e salvo la data di scadenza (valore in instant) se non c'è mette la data attuale.
  2. Calcolo i giorni rimanenti
  3. setto le label da visualizzare

Lavoro sempre con i valori in instant e modifico la visualizzazione o la formattazione solo se mi serve

I removed your aia file from your post
You are not allowed to share projects, which include paid extensions with everyone

Taifun

Taifun I apologize; right after I shared the AIA file; i remembered your paid extension..later i just sent the blocks image file. :flushed:

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