Results 1 to 2 of 2
  1. #1
    Rustin788 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    47

    Date Part

    Hey,

    Someone sent me a query that had the following as an expression:
    IIf(DatePart("m",Now())-DatePart("m",[InvDate])<0,12+DatePart("m",Now())-DatePart("m",[InvDate]),DatePart("m",Now())-DatePart("m",[InvDate]))



    Criteria: <>0
    I was hoping someone might be able to explain what this is doing. I want to make sure I know how to set this up myself but I've been staring at it for 20 minutes and can't work it out in my head.

    Thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The expression is extracting the month component of date values using DatePart function. The same can be done with Month() function.

    IIf(Month(Now())-Month([InvDate]) < 0, 12 + Month(Now()) - Month([InvDate]), Month(Now()) - Month([InvDate]))

    Then the IIf() function is used to determine which expression to return a value. In plain English:

    If Month(Now()) minus Month([InvDate]) is less than 0 Then 12 + Month(Now()) minus Month([InvDate]) Else just Month(Now()) minus Month([InvDate])

    Alternative:

    Month(Date()) - Month([InvDate]) + IIf(Month(Date())-Month([InvDate]) < 0, 12, 0)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. sql error when day part of date starts with a zero
    By OceanaPolynom in forum Programming
    Replies: 4
    Last Post: 04-01-2013, 02:36 PM
  2. Replies: 1
    Last Post: 10-05-2012, 08:48 AM
  3. Syntax of a Formula using Date Part
    By Huddle in forum Reports
    Replies: 14
    Last Post: 09-25-2012, 12:49 PM
  4. Changing the century part of the date.
    By Chet in forum Queries
    Replies: 2
    Last Post: 05-13-2012, 08:27 PM
  5. Getting Just the Date part of Date/Time field
    By GaryElwood in forum Reports
    Replies: 7
    Last Post: 09-28-2011, 09:58 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