+ Reply to Thread
Results 1 to 7 of 7

Datedif question

  1. #1
    Registered User
    Join Date
    04-11-2009
    Location
    Jordan, MN
    MS-Off Ver
    Excel 2003
    Posts
    2

    Datedif question

    Hello,
    I tried searching the forums before posting here but I came up empty handed.

    I have been using the formula below since last September without any problems; however, in the past month or so it has gotten to be a day behind (yes the pc clocks are correct).


    =DATEDIF(1/1/2009, NOW()-1, "YD")*132


    Instead of NOW()-1 i need NOW()-2 to get the appropriate numbers. At first I figured it was a leap year issue since the original date was 2008, so I updated the formula to 2009 and it still is not working. If I manually add up the days in the year and multiply by 132, it's not matching what this formula says.

    I have tried the formula on 3 different computers using Excel 2003 and Excel 2000, all with the same results.

    I also use the exact formula except with "MD" instead of "YD" and it calculates just fine.

    A quick background on the formula:
    I work at a hotel and we need a daily total for the year on the number of the rooms we have (132). This spreadsheet is only used the day after hence the NOW()-1.

    I'm sure there are other ways to get the correct number, but I am mainly just trying to figure out why this particular formula stopped working.


    Thanks in advance
    ~Chris
    Attached Files Attached Files
    Last edited by Theanrkist; 04-12-2009 at 02:14 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Datedif woes

    DATEDIF deals with dates only, and NOW() is a Date&Time function. First thing you should do is switch to TODAY() instead of NOW() since TODAY() is a Date only function.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Datedif woes

    I declared a Named range called BeginDate set at 1/1/2009 which allows it to be used in formulas and evaluated as if it were a cell value.

    Then I adjusted your formulas since there is no need to do the -1 thing, a DATEDIF formula always seems to lose a day...I typically have to ADD it back in with a +1. Since you want the date range to calculate through yesterday, the answer is already correct.

    C6:
    =DATEDIF(BeginDate, TODAY(), "MD")*B6

    D6:
    =DATEDIF(BeginDate, TODAY(), "D")*B6
    Attached Files Attached Files
    Last edited by JBeaucaire; 04-11-2009 at 08:22 AM.

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Datedif woes

    The problem with the formula

    =DATEDIF(1/1/2009, NOW()-1, "YD")*132

    is that 1/1/2009 isn't interpreted as a date but as a calculation, i.e. 1 divided by 1 divided by 2009 which evaluates to a small number, i.e. 0.0004977.....

    DATEDIF truncates this to zero which in Excel is effectively 31/12/1899. Because this is the last day of the year rather than the first your calculation is 1 out. Try putting the date in quotes, then it'll be recognised as a date, i.e.

    =DATEDIF("1/1/2009", NOW()-1, "YD")*132

  5. #5
    Registered User
    Join Date
    04-11-2009
    Location
    Jordan, MN
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Datedif woes

    Thank you both for the very quick responses!

    Both of your solutions worked, I can't thank you enough!





    ~Chris

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Datedif woes

    you can make this thread [solved]... That would be enought thanks

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Datedif woes

    Glad to help.

    If that takes care of your need, be sure to EDIT your original post (Go Advanced) and mark the PREFIX box [SOLVED]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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