Convert Text to Time and Filter

Posted on 2007-10-05
Last Modified: 2011-09-20
I have a fieldin a table with a datatype of Text that I can use the Format([CollectTime],"hh:nn:ss") function to successfully text to time.  However I need to filter this data in the same query.

For example >=#15:15:00#

When I do I do not get results even though I can see some would qualify.

Help this is urgent!
Question by:gpotenza
    LVL 92

    Expert Comment

    by:Patrick Matthews
    gpotenza said:
    >>datatype of Text

    If the data type is text, then why are you using a data type of datetime for the filter comparison?

    Compare text with text and datetime with datetime; when you try to mix them up you can get
    unexpected results.

    Author Comment

    The data in the field represents a time that I need to filter by a timespan. (for example from 15:00 to 20:00)  How would I do that if the field datatype is text?
    LVL 92

    Expert Comment

    by:Patrick Matthews
    If the text is stored as hh:mm, then try:

    [TimeField] Between "15:00" And "20:00"

    or if that does not work:

    [TimeField] >= "15:00" And [TimeField] <= "20:00"

    Why are you storing this as text and not as datetime?
    LVL 119

    Accepted Solution


    cdate([collectTime]) between #15:15# and #20:00#

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now