Results 1 to 15 of 15
  1. #1
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476

    Some help with Date calculation


    In my dealership dbs one of my fields is, ‘DatePurchased.’ From the ‘DatePurchased’ field I created a field ‘DOL’ (Days On Lot) which counts the days between the ‘DatePurchased’ to the current date: DOL: (Date()-[DatePurchased]). E.g. DatePurchased 8/27/2012, DOL 129. Now, how can I show (calculate) how many MONTHS have passed since ‘DatePurchased’ (or DOL) & the current date?
    Thanks in Advance

  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,652
    Try the DateDiff() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Hi Dave.
    You can't directly do the days to month conversion because different months have different number of days.
    If you want to get a reasonable approximation, you could divide your days calculation by 30, or 30.23( or you pick the value) and it'll be pretty close.

    The other option is
    MonthsOnLot = Datediff("M",DatePurchased,Date())

    I forget which Date has to be first. If this gives a negative number then reverse the Date order.


    Jeeez: I spent a few seconds reading this over and Paul has answered.. oh well.

  4. #4
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Much thanks pd & orange!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Hey pd &/or orange, I have another ? I have 2-flds in my dealership dbs, 1) 'StckNum' & 'VINNum' Now the 'StckNum" are the last 6-characters of the 'VINNum.' How/or is there a way that when I enter in the 'VINNum' the last 6-characters would automatically be entered in the 'StckNum'? If so, how would I go about?

  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,652
    I wouldn't save it, but:

    http://allenbrowne.com/casu-14.html

    Either way using the Right() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I wouldn't save/store it as a separate field either. If you have to report StckNum, as Paul says, Right(VinNum,6)

  9. #9
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    I'm confused, what's the problem with saving it?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Reasons:

    1. duplication of data

    2. data based on calculation of other data

    3. requires code to save calculated value

    4. saved value can become 'out of sync' with source data
    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.

  11. #11
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Hey June :-) I might be a fool, but I'll take the risk...

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    As Allen Browne notes in the referenced article, there are times when saving calculated value is justified. However, not seeing that in this case but if you must, something like:

    Me.StckNum = Right(VinNum,6)

    The real trick is figuring out what event to put the code in. Perhaps the AfterUpdate event of VinNum 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.

  13. #13
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Actually, I went to the Record Source & in the query changed the StckNum to [StckNm: Right([VinNumber],6)] It might not be right, but it's working for me. If it bites me in the a** I'll own up to it

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    That does not save data to table. That does what we were all advising, simply calculate the value in query.
    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.

  15. #15
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    As it bites me right in the A**, thanks

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

Similar Threads

  1. Date Calculation
    By mrkaye in forum Forms
    Replies: 5
    Last Post: 11-11-2010, 01:10 AM
  2. Date Calculation
    By mrkaye in forum Forms
    Replies: 4
    Last Post: 11-10-2010, 10:42 AM
  3. Date Calculation
    By mrkaye in forum Forms
    Replies: 4
    Last Post: 11-09-2010, 06:52 PM
  4. Date Calculation ?
    By techexpressinc in forum Queries
    Replies: 2
    Last Post: 06-24-2009, 09:02 PM
  5. Date Calculation -- HELP!
    By klaauser in forum Forms
    Replies: 0
    Last Post: 12-22-2008, 02:14 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