Results 1 to 9 of 9
  1. #1
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112

    Defining Time field format in the table


    Hello,

    I have a time-of-day field that I need to display without am/pm and without a 24-hour clock.
    I need to be able to sort on the field. (It is always a "day time" so sorting does not need am/pm)
    And I need to be able to combine the field into a string with other information.

    I am not sure how to define the original field in the table. Can I define it in this way right at the outset? Or must I to do it in every query, form, and report?

    Thanks for any help.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Time is ONLY stored 1 way. Its how you want to look at it.
    am/pm
    24 hrs
    etc

    it all sorts the same, it all adds the same, its just how you want to see it.
    you can view it a number. (its actually a decimal)
    format([timefld],"0.00000")

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am not sure how to define the original field in the table
    In the table, just define it as a date/time field. No formatting.
    It doesn't matter what it looks like in the table because users should never see/work with the table.
    Same with queries.

    In forms/reports, you (can) set formatting....... how you want it to look.

  4. #4
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112
    ok, I understand that about the table.
    But, can you tell me the format for simply hh:mm that won't convert afternoons to military time?

    (Sorry if I should only send the reply once.)





    Quote Originally Posted by ranman256 View Post
    Time is ONLY stored 1 way. Its how you want to look at it.
    am/pm
    24 hrs
    etc

    it all sorts the same, it all adds the same, its just how you want to see it.
    you can view it a number. (its actually a decimal)
    format([timefld],"0.00000")

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The closest I have been able to come is

    hh:nn - military time with two digits
    h:nn a/p - non-military time with one or two hour digit as required and two digit minutes

    In the format property I also tried:
    Code:
    =Left([TheTime],Len([TheTime])-6)
    and
    Code:
    =CSTR(Left([TheTime],Len([TheTime])-6))
    (change "TheTime" to your field name)
    but I don't know if these will meet your other requirements.

    You might have to use
    h:nn a/p



    Look at HELP. The hour defaults to military time.... adding "a/p" changes to non-military time but adds an "a" or "p" suffix.

  6. #6
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112
    Hello,
    This is posting from me is almost a year old, but I am still having trouble with the question of how to display time of day without AM/PM and without military time. (And without the tedious, ever-changing recoding that I have been using). I did as the immediately proceeding expert suggested: I put the expressions into the query (trying both suggestions) and they both do display as I had hoped. (Yeah!)
    Here are examples of my two statements (StartTimeAMPM is the date/time field, StartingTime is the created field)

    StartingTime: CStr(Left([StartTimeAMPM],Len([StartTimeAMPM])-6))

    StartingTime: Left([StartTimeAMPM],Len([StartTimeAMPM])-6)

    BUT, when I try to sort by either of these fields I get this error: "Data type mismatch in Criteria Expression." I see from the Database Documenter that they both become character strings, whether or not it is specified. So why wouldn't they sort as character string? (I realize that I wouldn't want to do this sort, since the times won't sort correctly, but I am worried about it not even being able to do it.)

    Does this seem to be a good way to go? Should I leave the actual time-field in the query for the sort? Should I be doing this in a text box in each report, separately, instead of in the query? And, do you see any other issues in doing it this way?

    I feel like I'm getting warm but still not there.
    Thanks!

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would try leaving the field "StartTimeAMPM" in the query, moving that column to the far right, setting the sort order and unchecking the SHOW check box.
    See if that is what you want.

  8. #8
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112
    Thanks! I will do as you suggest.
    Does it make a difference which of the two expressions (in my above message) I use?

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The only difference I see is that the first one ensures the result will be a string

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Defining an Array in an Access Table
    By EddieN1 in forum Database Design
    Replies: 9
    Last Post: 10-10-2014, 08:09 AM
  2. Replies: 1
    Last Post: 09-06-2012, 12:33 PM
  3. Defining Field Types In A Make Table Query
    By jo15765 in forum Queries
    Replies: 2
    Last Post: 05-23-2012, 08:07 PM
  4. Replies: 1
    Last Post: 08-07-2011, 07:58 AM
  5. progamatically defining a likned table
    By ajinc in forum Programming
    Replies: 1
    Last Post: 06-02-2011, 06:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums