Hy guys, I’m trying to build an app where users can pick a time range, e.g. 9:00 am to 5:00 pm. I can’t seem to get it to work. I don’t want the dates to be visible, I only want the time. I would be glad if someone could help.
A couple questions:
- Are you trying to do this with the default date/time picker functionality? That input always frustrates me; you’re right that it doesn’t let you show just a time. I usually end up building something from scratch for this kind of feature.
- Are you trying to pick a time range from a list of time ranges, or identify a time range as in selecting the start and end times independently and uniquely?
I can tell you that for identifying a time/time range, I would probably use either a dropdown with a long list of times (text datatype) or several inputs, and then do a bit of calculation to generate the right date/time datatype when the user manually saves.
Thank you for your suggestion, I thought of building something from scratch, I just wanted to know whether there’s a way to do it differently.
Regarding the calculations to get the right date, how would I get a m and/or p.m? Thank you.
The way I did it was to make a dropdown with two static choices, AM or PM, and then had a boolean expression in the calculation for ‘Dropdown’s value contains pm :formatted as number’ where the format as number gives 12 for a yes and a 0 for a no.
One quirk of the way I did this is that I had to add -12 hours if the time selected was 12pm or 12am, I think because 12am technically has an hours component of 0. That’s the second :formatted as number operator in there.
There may be an easier way to do it but this didn’t take too long to put together. My Hours input allowed integers from 1-12 and the Minutes input allowed 0-59. You could do this with dropdowns for the hours/minutes as well, if you wanted to force intervals of 15 minutes for example. It would take some extra work to do, but you could even have one dropdown with a list of times (all in text format, e.g. ‘9:15 am’ for a dropdown entry) and do some fancy ‘split by’ and ‘convert to number’ operations to get the hour and minute components.
(I know another way to do this is to make a datatype for times. That seemed unnecessarily complicated to me considering how many possible times there are, but there may be good reasons for it in other apps that I just haven’t run into yet with my own.)
Thank you so much for this, I’d definitely try it out.
No problem. I was working on this just yesterday so it was still fresh
Oh, one thing I should have mentioned from the start - technically speaking, you could use the default date/time picker and just… cover the date portion with a shape or other opaque group. That would work. I didn’t go that route because I wanted more flexibility but it’s an option.
Oh, that’s great, I’ll try both, thanks again buddy.
This topic was automatically closed after 70 days. New replies are no longer allowed.