Results 1 to 10 of 10
  1. #1
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78

    Calculated Field: Today() - [DOS]

    Can someone please assist me in the creation of a calculated field.

    The Calculated field needs to be: Today's Date - [DOS]

    I can't get these to work:

    =GetDate - [DOS]


    =Today() - [DOS]
    =Date() - [DOS]

    I get errors on all of the above attempts. Any help would be much appreciated. I am simply trying to calculate the days that have gone by since the [DOS]

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    If you are doing this in query, remove the = sign.
    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.

  3. #3
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78
    June7,

    Thanks for the reply.

    I'm trying to do it in an actual table field. Is this considered bad practice?

    I also tried this formula with no luck:

    =Format(Date(),"mm/dd/yyyy")-[DOS]

    If it matters..... [DOS] is in Short Date Format

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Some like, some don't. If you need to build db for backwards compatibility, is bad.

    However, not all functions are available to calculated field in table. If they don't show up in the expression builder, then not available. Date() is not an available function.

    You will have to do this calc in query or textbox.

    Today() is not even an intrinsic function, I don't know what GetDate is.

    Format() would result in a text value, not an actual date and that expression should fail even if used in query or textbox.
    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.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if you're storing the DOS (date of service) field why do you need to store the calculated field at all? You can just create it with any query/report you run on the data.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    rpeare, it is my understanding that Calculated field (introduced with Access 2010) expression dynamically recalculates when the raw data changes and does not store calculated result. However, I could be mistaken - according to Allen Browne http://allenbrowne.com/casu-14.html

    It is intended for simple calcs like Price * Quantity and not all functions are available.
    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.

  7. #7
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78
    I ended up putting in a Form TextBox as you suggested. =DATE()-[DOS] was the proper syntax.

    Thanks so much for the help.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    june, I believe the values *are* stored because the section dealing with:

    This may seem simple, but it creates more problems that it solves.....
    from that same article for various reasons

    states that if you change the calculation, all your existing data will not be converted at all which screams to me it's being stored. This is in conjunction with other problems also listed in that same article.

    Plus... I'm a minimalist and don't believe in storing anything I don't have to!


  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I've never used them but just did a simple test. Created Calculated field and saved table then modified the expression. Results re-calculated. So don't really know what Allen is warning about. Maybe this is one time Allen misses the mark.
    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.

  10. #10
    mrmmickle1's Avatar
    mrmmickle1 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Location
    North Carolina
    Posts
    78
    Thank you both for the valuable input. I appreciate it! This is good to know.

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

Similar Threads

  1. Replies: 2
    Last Post: 12-30-2014, 01:32 PM
  2. Replies: 3
    Last Post: 12-04-2012, 05:22 PM
  3. Replies: 5
    Last Post: 10-12-2012, 11:00 AM
  4. Replies: 7
    Last Post: 07-12-2012, 02:35 PM
  5. If problem-comparing field+1735<Today()
    By Madmax in forum Access
    Replies: 6
    Last Post: 06-23-2011, 01:38 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