+ Reply to Thread
Results 1 to 7 of 7

HELP! Dates are not calculating properly!!

  1. #1
    Forum Contributor her.rockstar's Avatar
    Join Date
    01-11-2013
    Location
    Saint John, NB
    MS-Off Ver
    Office 365
    Posts
    194

    HELP! Dates are not calculating properly!!

    I feel like I'm losing my mind!
    I'm trying to find the number of days in a month, but none of my formulas are responding properly.

    For example,

    =DAY(DATE(YEAR(2018),MONTH(2)+1,1)-1)
    Should return 28

    =DAY(DATE(YEAR(2018),MONTH(4)+1,1)-1)
    Should return 30

    =DAY(EOMONTH(A2,0)) (assuming A2 is 2)
    Should return 28



    NONE of these are working. They all return 31
    My workbook calculations are all set to automatic, I'm not seeing any errors, my clock is set properly on the PC.
    I try to evaluate the formula =DAY(DATE(YEAR(2018),MONTH(2)+1,1)-1), and this is what it says happens:


    =DAY(DATE(YEAR(2018),MONTH(2)+1,1)-1)

    =DAY(DATE(1905,1+1,1)-1)

    =DAY(DATE(1905,2,1)-1)

    =DAY(1859-1)

    =DAY(1858)

    =31

    It makes absolutely no sense.

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: HELP! Dates are not calculating properly!!

    You don't need YEAR and MONTH, they are causing the error.

    =DAY(DATE(2018,2+1,1)-1)

    edit:-

    To elaborate

    2018 is the date serial for 10 July 1905 so YEAR(2018) is 1905

    2 is the date serial for 2 Jan 1900 so MONTH(2) is still Jan (1)+ 1=2 (FEB)

    So your DAY formula is actually asking for (1 Feb 1905) -1 which is Jan 31
    Last edited by jason.b75; 08-16-2018 at 09:27 AM.

  3. #3
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: HELP! Dates are not calculating properly!!

    Is it because you actually have the words YEAR and MONTH in the calc?

    ie
    Please Login or Register  to view this content.
    gives 28


    EDIT: Darn you Jason!
    If someone has helped you then please add to their Reputation

  4. #4
    Forum Contributor her.rockstar's Avatar
    Join Date
    01-11-2013
    Location
    Saint John, NB
    MS-Off Ver
    Office 365
    Posts
    194

    Re: HELP! Dates are not calculating properly!!

    Thanks so much for the quick response!

    I'm trying the formula you provided above:
    =DAY(DATE(2018,3,1)-1), and it does give me 28, however, when I want to use variable information, it returns 31.

    =DAY(DATE(A5,AZ2,1)-1)

    In this case, A5 is 2018, and AZ2 is 2

  5. #5
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: HELP! Dates are not calculating properly!!

    Again the result is correct.

    AZ2 is 2, so the formula is referring to the day before 1 Feb. If you want the end of the month, then you need AZ2+1

  6. #6
    Forum Contributor her.rockstar's Avatar
    Join Date
    01-11-2013
    Location
    Saint John, NB
    MS-Off Ver
    Office 365
    Posts
    194

    Re: HELP! Dates are not calculating properly!!

    AHA! Perfect. Now it makes sense. Thank you so much!

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: HELP! Dates are not calculating properly!!

    Just a little FYI.

    Excel stores dates as serial numbers, by counting the number of days the date falls after 0 Jan 1900 (or as a real date, 31 Dec 1899).

    This means when you use a number that represents a partial date, i.e. only the month, but no day or year, that the result will most likely differ from that which you expect.

    Only the DATE() function can cope with partial dates, any others require a full date (day month and year) to be certain of correct results.

    For your original formula, =DAY(DATE(YEAR(2018),MONTH(2)+1,1)-1) to work, you would need to do it something like

    =DAY(DATE(YEAR(A2),MONTH(A2)+1,1)-1) or =DAY(EOMONTH(A2,0))

    With a proper Feb date in A2, (15 Feb 2018) in order to get the correct result of 28.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Product( ) not properly calculating
    By snuffnchess in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-08-2016, 02:34 PM
  2. [SOLVED] VLookup Not Calculating Properly
    By mycon73 in forum Excel General
    Replies: 7
    Last Post: 02-08-2016, 04:49 PM
  3. Date+Time not calculating properly
    By DoodlesMama in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-15-2015, 12:14 PM
  4. Data Table Not Calculating Properly
    By jh12 in forum Excel General
    Replies: 2
    Last Post: 09-23-2014, 04:58 AM
  5. [SOLVED] Totals not calculating properly
    By chadly72 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-12-2014, 09:36 AM
  6. [SOLVED] SUM Function not calculating properly
    By nazre in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-16-2013, 03:18 PM
  7. [SOLVED] Formulas not calculating properly
    By SueK in forum Excel General
    Replies: 2
    Last Post: 05-10-2005, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1