What I’m trying to do: calculate difference between two dates with component calendar
What I’ve tried and what’s not working:
output in label obteined is: 2 days, 0:00:00
I want an output as : 2 or 2 days
Code Sample:
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
miadata1 = self.date_picker_1.date
miadata2 = self.date_picker_2.date
giorni = miadata2-miadata1
self.label_10.font_size=8
self.label_10.text=giorni
This is not specific to Anvil, but a general Python question. For those, usually a Google search will give the answer. In this case, the top answer on Google says to use:
self.label_10.text=giorni.days
ok, i searched with no result
Salve,
Avevo la stessa problema poco fa. Mi son riuscito ad resolvere cosi:
from datetime import datetime
a = (datetime(data1) - datetime(data2)).days
Spero che l’auita.
EDIT:
Credo che @jshaffstall sta dicendo che si po fare semplicamente:
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
miadata1 = self.date_picker_1.date
miadata2 = self.date_picker_2.date
giorni = miadata2-miadata1
self.label_10.font_size=8
self.label_10.text=giorni.days