Results 1 to 9 of 9
  1. #1
    JerryZ is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5

    Working with dates

    This is my first post and I am learning to program Access 2010 on my own. So, please be gentle and very specific in your response.



    I have a date field. I want to filter that date field to give me the records that share today's day, regardless of year, and to present the year.

    FYI: This is for a "today in history" type of thing. I want to see the records I entered for events that occurred "today" in any given year.

    Thank you in advance for your help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    In a query, it would look like:

    WHERE Month(DateField) = Month(Date()) AND Day(DateField) = Day(Date())

    In a filter, same thing but without the word "WHERE".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JerryZ is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    I'll give that a shot.

    Thanks Paul

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No problem; post back if you get stuck. Welcome to the site by the way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    JerryZ is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    That worked for one date field but I can't get the other date field to work with OR. I have birth and death fields where I want one and/or both.

    Example: Jerry Jones (not that Jerry Jones) was born on this day in 1863. Billy Smith died on this day in 1999. The record for Jones shows in my query run but not Smith when I used

    WHERE (((Month([qry_Test]![DateOfBirth]))=Month(Date())) AND ((Day([qry_Test]![DateOfBirth]))=Day(Date()))) OR (((Month([qry_Test]![DateOfBirth]))=Month(Date())) AND ((Day([qry_Test]![DateOfBirth]))=Day(Date())));

    HAHAHAHAHA!! Never mind. After posting, I checked the fields and saw the problem. Fixed it and it worked....thanks.
    Last edited by JerryZ; 04-03-2011 at 04:12 PM. Reason: Caught mistake

  6. #6
    JerryZ is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    Thanks, Paul.

    OK, now I can't figure out how to extract the year from one or the other date field.

    When I run

    1. Year: Year([qry_Test]![DateOfBirth]) I get the year of birth in the new Year field.
    2. Year: Year([qry_Test]![DateOfDeath]), I get the year of death in the new Year field.
    3. Year: Year([qry_Test]![DateOfBirth]) OR Year([qry_Test]![DateOfDeath]), I get -1 in the new Year field for both Jones and Smith.
    4. Year: Year([qry_Test]![DateOfBirth] OR Year([qry_Test]![DateOfDeath])), I get 1899 in the new Year field for both Jones and Smith (Jones was born in 1863 and Smith died in 1999).

    I also tried replacing "OR" with "AND" and they both came back empty Year fields. I just want the year from either field. This can't be that difficult.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Which do you want? How about:

    TheYear: IIf(IsDate(DateOfDeath), Year(DateOfDeath), Year(DateOfBirth))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    JerryZ is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    I don't know how, but that worked. You are the man, Paul. Thanks again.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No problemo. Look up the IIf() and IsDate() functions in help and you'll understand how it works.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Sorting of dates no working?
    By Buakaw in forum Queries
    Replies: 7
    Last Post: 02-15-2012, 10:47 AM
  2. display all dates between two dates
    By KenThompson in forum Access
    Replies: 8
    Last Post: 02-23-2011, 01:11 PM
  3. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 PM
  4. Between dates using Iif
    By unique in forum Access
    Replies: 1
    Last Post: 01-04-2010, 07:17 AM
  5. Due dates
    By Mehbastan in forum Queries
    Replies: 5
    Last Post: 08-14-2009, 08:37 AM

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