Results 1 to 6 of 6
  1. #1
    Wilfred is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    1

    Cool Difference between two years

    My query is



    Service: DateDiff("yyyy",([Reg]),#1/1/2020#)

    Where "Reg" is registered year (ex. 2004) But I get the reply as 115. The reply should be 15 or suppose 16. " Service" is number of years served up to 1/1/2020.

    Please assist to get the correct answer.

    Thank you.

    Wilfred.

  2. #2
    Join Date
    Apr 2017
    Posts
    1,681
    2004 as date is 2004 days from 1st January 1905 (26th June 1915). Difference between years 2020 and 1905 is 115. So Access is right there!

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Wilfred View Post
    My query is

    Service: DateDiff("yyyy",([Reg]),#1/1/2020#)

    Where "Reg" is registered year (ex. 2004) But I get the reply as 115. The reply should be 15 or suppose 16. " Service" is number of years served up to 1/1/2020.

    Please assist to get the correct answer.

    Thank you.

    Wilfred.
    Something like:
    Code:
     Service: 2020-[reg]
    If you want it to work next year (2021) and subsequent years then:

    Code:
    Service: Year(Date())-[reg]
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Quote Originally Posted by ArviLaanemets View Post
    2004 as date is 2004 days from 1st January 1905 (26th June 1915). Difference between years 2020 and 1905 is 115. So Access is right there!
    However Access dates are counted from 30 Dec 1899 not 1 Jan 1905 so I don't think that makes sense. Perhaps you could explain
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Join Date
    Apr 2017
    Posts
    1,681
    Quote Originally Posted by isladogs View Post
    However Access dates are counted from 30 Dec 1899 not 1 Jan 1905 so I don't think that makes sense. Perhaps you could explain
    Sorry, a typo there as I was distracted!

  6. #6
    Cottonshirt is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Feb 2018
    Posts
    116
    if you want to calculate how many years have elapsed between the year represented by your 4-digit number [reg], and today,

    1. convert [reg] into a valid date by using the DateSerial() function: = DateSerial([reg],1,1)

    then use the DateFiff() function to calculate how many years there are between that date, and today,

    Code:
          DateDiff("yyyy",DateSerial([reg],1,1),Date())

    many thanks,


    Cottonshirt

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

Similar Threads

  1. Financial years
    By sdel_nevo in forum Queries
    Replies: 10
    Last Post: 01-10-2017, 09:28 AM
  2. Not Been Visited in over two years
    By angie in forum Queries
    Replies: 6
    Last Post: 05-04-2015, 10:23 AM
  3. Date dfference +4 years
    By sdc1234 in forum Queries
    Replies: 9
    Last Post: 11-20-2013, 11:34 PM
  4. fiancial years
    By Compufreak in forum SQL Server
    Replies: 4
    Last Post: 05-10-2013, 12:12 AM
  5. Select changes in the years
    By acs_one in forum Queries
    Replies: 8
    Last Post: 11-27-2010, 05:26 PM

Tags for this Thread

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