Solved Military time vs 24 hour time (1 Viewer)

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
In my current setup for an aircraft flight, the user enters a wheels up time and a wheels down time. I currently use a 24 hour clock time in that the user enter 22:20 for 10:20 PM including the entry of the colon. A change has been requested that the system allow for the entry of military time which would call for the entry of a 4 digit number from 0000 to 2359 without the entry of a colon and of course ensuring that the user does not specify a time between xx60 and xx99. After entry, I need to find the difference between the two times in minutes which causes a problem in that 1345 to 1423 is 38 minutes rather than 78 if i did a straight subtraction between the two values. I will have to change the database field definitions from a date-time field to a numeric field (or a text field) as well.

I could create a bunch of code to deal with this. However, I was wondering whether someone has run across this issue and has a simple soultion,

thanks
 

ebs17

Well-known member
Local time
Today, 20:38
Joined
Feb 7, 2020
Messages
1,949
A time is managed using the Date (DateTime) data type. Internally, this is converted to a number of type double, where integers are the past days since 1899-12-30, times are then the decimal parts (parts of a day). The values are usually displayed using country-specific fixed formats. This is only for the introductory explanation.

In this sense, 2359 is not an accepted format for a time and thus cannot go into a table in a date field. But you can enter the sequence of digits, understand them as text and convert this text into a time, for example
Code:
? Format("2359", "@@:@@"), CDate(Format("2359", "@@:@@"))
23:59         23:59:00
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:38
Joined
Feb 19, 2013
Messages
16,618
To build on Eberhard's solution
?(cdate(format(1423,"@@:@@"))-cdate(format(1345,"@@:@@")))*1440
38


1440 is number of hours in the day * number of minutes in an hour

or

?datediff("n",cdate(format(1345,"@@:@@")),cdate(format(1423,"@@:@@")))
38


gets more complicated if the times are split over midnight - but no way to tell from just the time whether or not this is the case. Although if the end time is less that the start time, it would be a reasonable assumption
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:38
Joined
Feb 19, 2002
Messages
43,297
Is the pilot doing the data entry as he leaves the runway? Isn't that distracting? Same question for landing?

Are they asking for military time because they don't want the distraction of having to enter the punctuation? Richard's solution handles that.

When I want to do quick entry for date or date/time, I use the double-click event of the control and either enter Date() or Now(). That gives you a simple way to enter both start/end times and has the advantage of including date so you automatically handle crossing midnight because you can just do date arithmetic using datediff() to get the number of minutes between takeoff and landing. If you want, you can use separate date and time fields and add them together before you subtract the start from the end to get the total minutes.
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
The masking and formatting by Richard Rost should work with minimal impact to the app.

As far as I know, the pilot has a knee pad where they mark down all the relevant information for later transfer to their log book. Not being a pilot myself, I figured 24 hour clock was correct - my brother has been entering the bloody colon for two years on a spreadsheet and now agrees with his wife (who is also a pilot) that military time is better. As the approach by Richard does not change the definition of the time field, all of my existing code for time manipulation will work as in the datediff function.

Thanks for the simple solution
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
I changed the input mask to 00:00 and the display format to hhnn. As shown in the video, when I enter a value in the field like 0823, it actually appears as 08:23 when I type it in and goes back to 0823 when I leave the field. However, this works when I go to the table directly and enter a record. When entering data in a multi row form, I enter 0823 and I get an error message “The value you entered isn’t valid for this field”. What do I have to change to make this work on my form?
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
Also, times with a Leading zero do not display the zero. 07:30 is shown as 730 instead of 0730.
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
Ah, I need to set the input mask on the form as well.

the only issue seems to be the invisible leading zero. Any suggestions?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:38
Joined
Feb 19, 2013
Messages
16,618
As a number, the value is suspect and needs to be converted anyway for use in calculations. So I would be inclined to store it as text
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:38
Joined
May 7, 2009
Messages
19,245
here is a simple validator/converter.
 

Attachments

  • inputTime.accdb
    584 KB · Views: 105

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
ArnelGP, the code works as advertised. Thank you

however, it introduced a problem that I have had before and not sure how to deal with.

I am entering the data on a continuous form. I created two new unbound fields for the wheels up and down times, leaving the original fields hidden. The idea is that the user enters the data, it is validated, the validates times are generated and stored in the short time database fields. That works like it should. The problem is that the value entered by the user in the two Unbound fields is also being displayed in all record Instances (including the bottom line for new entries) shown on the continuous form. Is there a way to make the unbound field values only displayed for the current record only?
 

ebs17

Well-known member
Local time
Today, 20:38
Joined
Feb 7, 2020
Messages
1,949
Why are the tips in the video praised if they are not implemented? Consider the behavior when entering in form frmTimes and directly in table.
Note: I have been instructed and corrected, compared to #3.

Question by the way: Why do sample files come from respondents but rarely from questioners? By example file, I mean a concentration of the content on exactly what is necessary for the problem, not the overall project of a questioner (the whole and often confusing pile)?
 

Attachments

  • inputTime_V2.zip
    23.5 KB · Views: 88
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:38
Joined
Feb 19, 2002
Messages
43,297
Is there a way to make the unbound field values only displayed for the current record only?
The continuous form is ONE form displayed for each row. Therefore, it has only ONE set of properties so there can be only one value for an unbound control. Try setting the unbound control to null after transfering the data. The rows will all change to null. This may be less disconcerting. Otherwise, you need to make bound columns.

Why do sample files come from respondents but rarely from questioners? By example file, I mean a concentration of the content on exactly what is necessary for the problem, not the overall project of a questioner (the whole and often confusing pile)?
The answer is simple. The expert can put together a simple form example in a few minutes and the posters can't. So, it can be very difficult for them to isolate a non-working object. We're happy if they can cut down the data and compact and zip the file:) Plus some of our most prolific helpers are not comfortable with English and so an actual sample is less trouble than trying to write an explanation.
 

ebs17

Well-known member
Local time
Today, 20:38
Joined
Feb 7, 2020
Messages
1,949
So, it can be very difficult for them to isolate a non-working object.
If a poster ever wants to solve a problem himself, he must be able to isolate that problem. He will hardly be able to rely on the chance of hitting the target with shots in the fog. So such an ability would be very helpful for him.

Of course, he can also keep his status quo and call for the lifebuoy at every drop of water.

Here in the example: A table, plus a bound form. This should be solvable for every newbie.
 

Isaac

Lifelong Learner
Local time
Today, 11:38
Joined
Mar 14, 2017
Messages
8,779
If a poster ever wants to solve a problem himself, he must be able to isolate that problem. He will hardly be able to rely on the chance of hitting the target with shots in the fog. So such an ability would be very helpful for him.

Of course, he can also keep his status quo and call for the lifebuoy at every drop of water.

Here in the example: A table, plus a bound form. This should be solvable for every newbie.

While perhaps hard to hear, I like the points Eberhard is making.

We want to be friendly to newcomers, but in way too many cases we take the easier (?) route [for us], which is to provide a direct and limited solution, or provide a bunch of solutions and hope one might be right, without challenging the question, because often developers enjoy being problem solvers.

What would actually improve the development-character of the asker is challenging them how to troubleshoot, isolate, define, reference, and present an extremely thoughtful product of that isolation/definition to the community-at-large.

This can feel awkward, and I'm familiar with the occasional backlash that comes with doing so, but ebs is not wrong and deserves to be supported in this.
 

ebs17

Well-known member
Local time
Today, 20:38
Joined
Feb 7, 2020
Messages
1,949
It is also not uncommon for a poster to receive a solution database but not be able to integrate the solution into his real database.
One might think that the poster could do a little more with the installation of the solution in its sample file.

@PaquettePaul: Sorry if I'm just writing such general thoughts in your topic. This is not a personal thing.
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
All useful responses to a problem should be praised, whether the full response is used or not. I never used the input mask for data entry before and found it useful. Same with the simple validation in the sample database. The responses provide me with an option that i did not know before - both of them are simpler than I thought would be the case.

If I knew about this user ”need” for military time data entry, then I would more than likely have used arnelgp’s solution from the start and had a 4 character text fields rather than using short time fields. At this stage where the end user has started using the application, then any changes to the data structure are more problematic as myself, the brother installing the application remotely, and the end user are in three different states/provinces.

I thought the solution provided in arnelgp’s database would be better given its simplicity, but the issue of unbound fields makes it a non starter. While I am not enthusiastic about the full time display when entering a short time field, the field format and input mask solution seems to ”fit” my current predicament, causing the least amount of change.

my appreciation and thanks for the responses
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
Btw, I did copy arnelgp’s code in my general function routine so that I do not lose it.
 

PaquettePaul

Member
Local time
Today, 14:38
Joined
Mar 28, 2022
Messages
107
Ebs17, given the complexity of my forms, stripping the app to a simple database to demonstrate the problem would be a lot of work. I could have provided an image of my form to demonstrate the issue but images are frowned upon. So, I try to explain the issue as clearly as possible but not always successfulply.
 

Users who are viewing this thread

Top Bottom