Extract the hours and minutes

I want to extract the hours and minutes from a selected date and time using date and time components. Is that possible?

As per the screenshot, I want in this way -

Hours - 18 and Minutes - 53

Plenty of custom formula calcs and INT( ) functions. That’s how. I’ve put it on the link above. :+1:

Hi @Rozza ,

Fantastic! I really appreciate your help. However, I noticed that it only shows the current time. What if the date is in the past, like 10/02/1990?

I’m getting the incorrect hour.

Thanks
Shantanu

Yes I see, sorry I haven’t used a selectable date.

This is more complicated because date picker cannot

  • load a date from the database
  • update a input box
  • pass ‘start of day’

So you need a button action to save the date/time to the database, then either load that into the start of your formula or into the first input box AND subtract the start of that date (another calculation)

OR
Nocodemonkey time picker component, gives you hour and minute outputs.

image

Hi,

I’m aware of the nocode monkey component but apart from this, I am storing the DOB in the database but still not working.

Yes I forgot to add this crucial aspect. Because “start of day” is not available for an existing date, only now()

Hi,

That means it is not possible to fetch using the same formula if the date is in past.

On the contrary. StoredDateTime-INT(StoredDate) will give the decimal part only, hence… you have the time portion for further calculation.

19634.645833333332

19634 = days past 1/1/1970
0.645833333332 = time, as a decimal portion of the day

19634.5 = noon today UTC time.

Unfortunately this is more complicated than it seems.

First, if you’re using the formula to compare start of today and now, this formula won’t work on 2 days in a year in countries with summer time change. The change occurs at 2 am, so the difference will be calculated incorrectly.
Hint: use tomorrow for hours calc difference :slight_smile:

Second, using just INT to get the current date won’t work correctly in all cases. For example, on 5th of October 1:30 AM GMT +3 will still be 19634.9378… (because it is still 4th of October in UTC). If we apply INT, we get 4th of October.

There is a workaround here - you can calculate the Timezone of a user device and apply it. Here are a couple of screenshots:

On the 2nd one you can see that hours are 25 - you can use modulo formula to transform it to 1 (sorry, was too lazy to do that).

However: the biggest issue with all these workarounds are that they are very unreliable. Adalo datetime components and formulas could be quite glitchy and may work differently on different platforms (!). I had numerous issues with them. For example, the latest one I have that date picker on iOS was returning full datetime value with a different offset every time I tap on it. Or I remember on some Windows version with some browser start of today was not in UTC. Or once I had a one day offset because of a double-conversion, and it was noticeable only on some timezones.

So based on my personal experience I’d suggest using a 3rd party API which gets the date in text, parses it and returns the values required. Or you can find some component (or write one) to implement this functionality.

Best,
Victor.

1 Like

Thanks for sharing your depth of knowledge on this Victor. Your post should be pinned :pushpin:

Hi,

Thank you, @Rozza and @Victor, for your contributions. This will definitely help me and future creators. I think its a better idea to use a component or API to retrieve the data.

Thanks
Shantanu

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