My time field has extra zeros (1 Viewer)

Lkwdmntr

Registered User.
Local time
Yesterday, 17:20
Joined
Jul 10, 2019
Messages
281
Hi, I have a time field that I pulled in from a table. when I run the query it gives me 2 extra zeros. ie: 7:00:00 AM

Not sure how to fix this. The fields name is StartTime and I tried StartTime:Format([StartTime], "hh:mm AM/PM") with no success.

Any help would be appreciated.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:20
Joined
Oct 29, 2018
Messages
21,467
Hi. You could try:
Code:
Start_Time:Format([StartTime], "hh:nn AM/PM")
 

Lkwdmntr

Registered User.
Local time
Yesterday, 17:20
Joined
Jul 10, 2019
Messages
281
Hi. You could try:
Code:
Start_Time:Format([StartTime], "hh:nn AM/PM")
is that supposed to be an "nn" or is that a typo?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:20
Joined
Feb 28, 2001
Messages
27,172
Just by way of explanation, if you got hh:nn:ss AM/PM as a format, it was probably due to your computer's regional settings selecting that format. And the reason it is "nn" for minutes is because it is "mm" for months. Using an explicit FORMAT function overrides the regional settings.
 

Isaac

Lifelong Learner
Local time
Yesterday, 17:20
Joined
Mar 14, 2017
Messages
8,777
You can also use: h:mm AM/PM
 

isladogs

MVP / VIP
Local time
Today, 01:20
Joined
Jan 14, 2017
Messages
18,216
Although Isaac's suggestion does work, in my opinion it would be better to use e.g. h:nn AM/PM
Here are some examples
Code:
?Format(Time, "h nn AM/PM")
8 27 AM
?Format(Time, "h mm AM/PM")
8 27 AM
?Format(Time, "nn AM/PM")
28 AM
?Format(Time, "mm AM/PM")
12 AM
?Format(Time, "mmm")
Dec

I'm not sure what is going on with the last 2 examples but it certainly isn't what you'd expect!
 

onur_can

Active member
Local time
Yesterday, 17:20
Joined
Oct 4, 2015
Messages
180
There is an error in your spelling. It should be "nn" instead of "mm". Also, there should not be any spaces between AM / PM expressions.
 

Attachments

  • query.JPG
    query.JPG
    61.2 KB · Views: 119
  • query_result.JPG
    query_result.JPG
    32 KB · Views: 92

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 01:20
Joined
Sep 12, 2006
Messages
15,652
obviously the extra zeroes represent seconds, so the default format is hh:nn:ss - so to get something else, you need a slightly different format.
 

isladogs

MVP / VIP
Local time
Today, 01:20
Joined
Jan 14, 2017
Messages
18,216
Going back to post #1, I forgot to say that
1. you can format the field as Medium Time in the table giving displayed value like 11:07 AM, 06:15 PM
2. you can't use the same name StartTime for a query field alias as the field name itself. Notice how DBG modified it in post #2
 
Last edited:

onur_can

Active member
Local time
Yesterday, 17:20
Joined
Oct 4, 2015
Messages
180
Friends, I explained the solution to the problem with images. I think this is the solution. I think there will be no problem if the Lkwdmntr friend applies this solution.
 

Lkwdmntr

Registered User.
Local time
Yesterday, 17:20
Joined
Jul 10, 2019
Messages
281
Wow! I just want to thank everyone for their responses. I certainly better understand the formatting process. I ended up using
Time: Format([StartTime],"h:nn AM/PM")
Worked like a charm. Thanks again.
 

isladogs

MVP / VIP
Local time
Today, 01:20
Joined
Jan 14, 2017
Messages
18,216
We were all pleased to help. Good luck with your project
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:20
Joined
Oct 29, 2018
Messages
21,467
Wow! I just want to thank everyone for their responses. I certainly better understand the formatting process. I ended up using
Time: Format([StartTime],"h:nn AM/PM")
Worked like a charm. Thanks again.
Hi. Glad to hear you got it sorted out. Just FYI, "Time" is a *reserved* word in Access. You might consider using a different name for your column to avoid any issues in the future.

Good luck with your project.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 01:20
Joined
Sep 12, 2006
Messages
15,652
Wow! I just want to thank everyone for their responses. I certainly better understand the formatting process. I ended up using
Time: Format([StartTime],"h:nn AM/PM")
Worked like a charm. Thanks again.
you want "hh" rather than just "h", don't you?
 

isladogs

MVP / VIP
Local time
Today, 01:20
Joined
Jan 14, 2017
Messages
18,216
Yup. Using e.g. hh just ensures two digits are always shown including a leading zero where appropriate
For example

Code:
?Format(Time,"h:n:s")
20:7:18

?Format(Now,"d m yyyy h:n:s")
25 3 2021 20:9:10

But here's two odd ones. See what its doing with the year?
Code:
?Format(Now,"d m y h:n:s")
25 3 84 20:11:37

?Format(Now,"d m yyy h:n:s")
25 3 2184 20:11:54
 

isladogs

MVP / VIP
Local time
Today, 01:20
Joined
Jan 14, 2017
Messages
18,216
Hi Isaac.
Yes that is of course correct ... but it isn't necessarily obvious to users who mistakenly type e.g yyy instead of yy or yyyy
 

Users who are viewing this thread

Top Bottom