Results 1 to 8 of 8
  1. #1
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27

    Comparing Date with current Date

    Hi Everyone. I have a table and one of the fields is a date field. I need to create a query based on this table such that only records from the current year is displayed. So I need to retrieve the year part from the
    date and compare with the current date. I m not too sure on how to do this esp the retrieving of year part from the date. Hope someone could guide me on this! Thanks

  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,521
    You can use the Year() function to get the year from both.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    Hey thank you very much! works perfectly fine!

    Year([Fieldname])=Year(Date())

  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,521
    No problem, happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    sorry I have another doubt regarding this. The thing is in another form, I could like the report to display records that have have the same year as the one the user inputed in the form. Therefore I wrote a criteria in the query ( which the report is based on). This is what I wrote:
    Year("PODate")=[Forms]![ContentPage(Opex)]![Year]

    However, it is giving an error msg saying either the expression is wrong or too complex. Could someone guide me on what I might be doing.

    Thanks

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not sure where you're using it, but almost certainly you don't want the quotes around the field name:

    Year([PODate])=[Forms]![ContentPage(Opex)]![Year]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ds_8805 is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2010
    Posts
    27
    ohhhh I just realised my mistake! that solved the problem! Thanks alot!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, glad we got it sorted out.
    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. Replies: 9
    Last Post: 03-19-2010, 10:37 AM
  2. VB coding to show current date n time in access form
    By cwwaicw311 in forum Programming
    Replies: 6
    Last Post: 02-10-2010, 09:53 PM
  3. Current Date Error
    By McFly in forum Database Design
    Replies: 4
    Last Post: 02-04-2010, 09:08 AM
  4. Changing a date to the current year
    By fdnyfish in forum Access
    Replies: 1
    Last Post: 03-01-2008, 08:34 AM
  5. Replies: 1
    Last Post: 12-09-2005, 10:29 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