• Excel weirdness (2002 SP2)

    Author
    Topic
    #395525

    I’m trying to get the month value from a date, but all I’m getting is ‘Jan’ or ‘1’ depending on how I format the cell. I have a date in cell A1, formatted as a date, and when I enter the formula ‘=MONTH(A1)’ in another cell all I get is the value for January, regardless of the actual date. I have tried the DAY and YEAR functions in other cells and they work correctly. What’s going on here?

    Other weirdness: after the screensaver kicks in, when I move the mouse or hit a key, Excel comes back in a window about one quarter the size I had it before the screensaver started. That’s with Excel in a window, not full screen. This only happens with Excel; Word and Outlook come back the way they were. Any ideas?

    Viewing 5 reply threads
    Author
    Replies
    • #734625

      Please post a spreadsheet demonstrating your problem.

    • #734626

      Please post a spreadsheet demonstrating your problem.

    • #734650

      If you have a date in A1 and then B1=Month(A1) should return 1 or Jan, as long as the month of your date in A1 is January something. When you change A1 to July something, then B1 should return 7 or Jul.

      If this is NOT happening take a close look at A1. Is it a real date? or perhaps text?

      Paul

    • #734651

      If you have a date in A1 and then B1=Month(A1) should return 1 or Jan, as long as the month of your date in A1 is January something. When you change A1 to July something, then B1 should return 7 or Jul.

      If this is NOT happening take a close look at A1. Is it a real date? or perhaps text?

      Paul

    • #734772

      If you format cell A1 as “general” what does it display?

      Steve

      • #735006

        If the cell containing the date is formatted as general, it displays the date in serial number format. See the file dates.xls I have posted.

        • #735054

          The value in the cells in C are correct. You have them formatted as “mmm”

          The month is 10 (c11) for cell A11. You formatted the value 10 to “mmm” so it formats it as a date and the 10th day is Jan 10,1900 so displayed as “mmm” it is Jan.

          You can display a11 as “mmm” and it will display Oct. so instead of month(a11) just use = A11 and format as “mmm”

          Steve

          • #735184

            OK, but that doesn’t help. I want to display the month as 3 letters (Oct, Jan, etc.). If I format the day column as dd, it displays the date (26, 27, etc.); if I format it as ddd, it displays the day of the week (Mon, Tue, etc.). How do I get the month to display as 3 letters?

            • #735188

              Format it as “mmm”.

            • #735189

              Format it as “mmm”.

            • #735190

              Steve gave you the answer in post 306188. I’ll spell out the details for you.

              Don’t use formulas like =MONTH(A1) in column C.
              Instead, enter =A1 in cell C1, and fill down to C12.
              Select C1:C12.
              Select Format | Cells…, Number tab.
              Select the Custom category.
              Enter mmm in the Type box.
              Click OK

            • #735281

              (Edited by MarkD on 25-Oct-03 10:58. Added additional note.)

              One additional note, if you can’t use cell formatting, such as when concatenating the date in a text string, you can use the TEXT function to specify correct format for any numerical value (including dates). Example:

              Cell A1 = 1/1/2003
              Formula =TEXT(A1,”mmm”) returns “Jan”
              Cell A365 = 12/31/2003
              Formula =TEXT(A365,”mmm”) returns “Dec”

              I had similar problem when trying to format date value (mm/dd/yyyy) as an “ordinal” date, ie, 1/1/2003 = January 1st, 2003, or 12/31/2003 = December 31st, 2003, etc. Since this “ordinal” date is derived by concatenating various values together could not rely on cell formatting to format the month portion of date. Wound up with a somewhat convoluted formula (the ordinal number part of equation borrowed from Walkenbach or I’d still be trying to get the formula correct):

              =TEXT($A1,”mmmm”)&” “&DAY($A1)&IF(OR(VALUE(RIGHT(DAY($A1),2))={11,12,13}),”th”,IF(OR(VALUE(RIGHT(DAY($A1)))={1,2,3}),CHOOSE(RIGHT(DAY($A1)),”st”,”nd”,”rd”),”th”))&”, “&YEAR(($A1))

              where column A contains the actual date values. The formula returns “date” (text) as January 1st, 2003, etc. Note use of TEXT function to return month, spelled out as “January”, etc by specifying “mmmm” as format.

              PS: Note that as name implies, the value returned by the TEXT function is text, not a number, and therefore cannot be used in calculations, etc.

              HTH

            • #735282

              (Edited by MarkD on 25-Oct-03 10:58. Added additional note.)

              One additional note, if you can’t use cell formatting, such as when concatenating the date in a text string, you can use the TEXT function to specify correct format for any numerical value (including dates). Example:

              Cell A1 = 1/1/2003
              Formula =TEXT(A1,”mmm”) returns “Jan”
              Cell A365 = 12/31/2003
              Formula =TEXT(A365,”mmm”) returns “Dec”

              I had similar problem when trying to format date value (mm/dd/yyyy) as an “ordinal” date, ie, 1/1/2003 = January 1st, 2003, or 12/31/2003 = December 31st, 2003, etc. Since this “ordinal” date is derived by concatenating various values together could not rely on cell formatting to format the month portion of date. Wound up with a somewhat convoluted formula (the ordinal number part of equation borrowed from Walkenbach or I’d still be trying to get the formula correct):

              =TEXT($A1,”mmmm”)&” “&DAY($A1)&IF(OR(VALUE(RIGHT(DAY($A1),2))={11,12,13}),”th”,IF(OR(VALUE(RIGHT(DAY($A1)))={1,2,3}),CHOOSE(RIGHT(DAY($A1)),”st”,”nd”,”rd”),”th”))&”, “&YEAR(($A1))

              where column A contains the actual date values. The formula returns “date” (text) as January 1st, 2003, etc. Note use of TEXT function to return month, spelled out as “January”, etc by specifying “mmmm” as format.

              PS: Note that as name implies, the value returned by the TEXT function is text, not a number, and therefore cannot be used in calculations, etc.

              HTH

            • #735331

              OK, I don’t need to use a function at all, just format the cell the way I want it to appear. However, that doesn’t solve my problem. The reason I was trying to use a function was because I am trying to calculate the number of whole months between two dates. The formula =(A1-A2)/(365/12)-0.5 isn’t accurate, as it doesn’t take account of leap years. For example, if the two dates are 3/17/1994 and 11/16/2006, this formula produces the result 152, but the correct result is 151.

            • #735332

              OK, I don’t need to use a function at all, just format the cell the way I want it to appear. However, that doesn’t solve my problem. The reason I was trying to use a function was because I am trying to calculate the number of whole months between two dates. The formula =(A1-A2)/(365/12)-0.5 isn’t accurate, as it doesn’t take account of leap years. For example, if the two dates are 3/17/1994 and 11/16/2006, this formula produces the result 152, but the correct result is 151.

            • #735335

              Try
              =DATEDIF(startdate,enddate,”m”)

            • #735342

              Thanks. That’s exactly what I needed. But where is it documented? It doesn’t show up in the list of available functions. Are there any other undocumented functions?

            • #735346

              DATEDIF is a strange case. It has been available in all recent versions of Excel, but it has been documented only in the online help for Excel 2000, not in Excel 97 or Excel 2002. How’s that for consistency?

              See The DATEDIF Function for details.

            • #735373

              You could also try =INT(12*YEARFRAC(date1,date2))

            • #735379

              Your formula is promising, but it doesn’t return the same result as DATEDIF:

              Date1 Date2 DATEDIF YEARFRAC
              02/28/2003 03/29/2003 1 0

              The DATEDIF formula returns the correct result. I tried setting the third argument of YEARFRAC, but couldn’t find a setting that always returns the correct value.

            • #735966

              I don’t think DATEDIF always gives the expected answer. Here is a quick example:

              12/31/2002 1/31/2003 1 1
              12/31/2002 2/28/2003 1 1.93333333333333
              12/31/2002 3/31/2003 3 3
              12/31/2002 4/30/2003 3 4
              12/31/2002 5/31/2003 5 5
              12/31/2002 6/30/2003 5 6
              12/31/2002 7/31/2003 7 7
              12/31/2002 8/31/2003 8 8
              12/31/2002 9/30/2003 8 9

              I apologize if the above is hard to read, but the first 2 columns are dates, the third column is =DATEDIF(a1,b1,”m”), and the fourth column is =12*YEARFRAC(A1,B1). It appears that DATEDIF only increments when the day of the second date equals the day of the first date. While this is easy enough to explain, most people would say that there are 2 whole months from 12/31/02 to 2/28/03. In this specific example, I think YEARFRAC gives better answers, except for the second row. In other examples, DATEDIF would do better. It’s clear to me that both options give imperfect results. I think this discussion indicates that you need to be very careful with counting months since the definition of a month varies.

            • #735978

              Thanks for these examples. I agree with your conclusion.

            • #735979

              Thanks for these examples. I agree with your conclusion.

            • #736008

              These are exactly what I would expect from datedif.

              It is like a birthday. You do not go up a year until the exact date. Anytime before your birthday, you “have not aged”.

              When you have:
              12/31/2002 to 4/30/2003
              You have not reached the 31st day of April so you have not finished the 4th month, so it is only 3 months difference. the function does not round, it truncates (again. like a birthdate)

              You can do alot more with datediff: this formula (eg):
              =DATEDIF(A1,NOW(),”y”) & ” years, ” & DATEDIF(A1,NOW(),”ym”) & ” months, ” & DATEDIF(A1,NOW(),”md”) & ” days”

              will display the number years, months, and days from the date in A1 to now.

              I do agree whole-heartedly with your point, it is important to know what you are asking for before you pick a formula.

              Steve

            • #736009

              These are exactly what I would expect from datedif.

              It is like a birthday. You do not go up a year until the exact date. Anytime before your birthday, you “have not aged”.

              When you have:
              12/31/2002 to 4/30/2003
              You have not reached the 31st day of April so you have not finished the 4th month, so it is only 3 months difference. the function does not round, it truncates (again. like a birthdate)

              You can do alot more with datediff: this formula (eg):
              =DATEDIF(A1,NOW(),”y”) & ” years, ” & DATEDIF(A1,NOW(),”ym”) & ” months, ” & DATEDIF(A1,NOW(),”md”) & ” days”

              will display the number years, months, and days from the date in A1 to now.

              I do agree whole-heartedly with your point, it is important to know what you are asking for before you pick a formula.

              Steve

            • #736231

              Very Interesting! Now try this formula:

              =DATEDIF(0,B3,”m”)-DATEDIF(0,A3,”m”)

              Microsoft was very lazy in designing DATEDIF!

            • #736346

              [indent]


              Microsoft was very lazy in designing DATEDIF!


              [/indent]I guess you have to blame Lotus123 for that, Datedif is only there for reasons of compatibility with that product. The same reason why Excel’s dates are wrong for 1900, thinking 1900 is a leap-year. This too is inherited for compatibility reasons (the wrong reason, I agree)

            • #736347

              [indent]


              Microsoft was very lazy in designing DATEDIF!


              [/indent]I guess you have to blame Lotus123 for that, Datedif is only there for reasons of compatibility with that product. The same reason why Excel’s dates are wrong for 1900, thinking 1900 is a leap-year. This too is inherited for compatibility reasons (the wrong reason, I agree)

            • #736232

              Very Interesting! Now try this formula:

              =DATEDIF(0,B3,”m”)-DATEDIF(0,A3,”m”)

              Microsoft was very lazy in designing DATEDIF!

            • #735967

              I don’t think DATEDIF always gives the expected answer. Here is a quick example:

              12/31/2002 1/31/2003 1 1
              12/31/2002 2/28/2003 1 1.93333333333333
              12/31/2002 3/31/2003 3 3
              12/31/2002 4/30/2003 3 4
              12/31/2002 5/31/2003 5 5
              12/31/2002 6/30/2003 5 6
              12/31/2002 7/31/2003 7 7
              12/31/2002 8/31/2003 8 8
              12/31/2002 9/30/2003 8 9

              I apologize if the above is hard to read, but the first 2 columns are dates, the third column is =DATEDIF(a1,b1,”m”), and the fourth column is =12*YEARFRAC(A1,B1). It appears that DATEDIF only increments when the day of the second date equals the day of the first date. While this is easy enough to explain, most people would say that there are 2 whole months from 12/31/02 to 2/28/03. In this specific example, I think YEARFRAC gives better answers, except for the second row. In other examples, DATEDIF would do better. It’s clear to me that both options give imperfect results. I think this discussion indicates that you need to be very careful with counting months since the definition of a month varies.

            • #735380

              Your formula is promising, but it doesn’t return the same result as DATEDIF:

              Date1 Date2 DATEDIF YEARFRAC
              02/28/2003 03/29/2003 1 0

              The DATEDIF formula returns the correct result. I tried setting the third argument of YEARFRAC, but couldn’t find a setting that always returns the correct value.

            • #735374

              You could also try =INT(12*YEARFRAC(date1,date2))

            • #735347

              DATEDIF is a strange case. It has been available in all recent versions of Excel, but it has been documented only in the online help for Excel 2000, not in Excel 97 or Excel 2002. How’s that for consistency?

              See The DATEDIF Function for details.

            • #735343

              Thanks. That’s exactly what I needed. But where is it documented? It doesn’t show up in the list of available functions. Are there any other undocumented functions?

            • #735336

              Try
              =DATEDIF(startdate,enddate,”m”)

            • #735191

              Steve gave you the answer in post 306188. I’ll spell out the details for you.

              Don’t use formulas like =MONTH(A1) in column C.
              Instead, enter =A1 in cell C1, and fill down to C12.
              Select C1:C12.
              Select Format | Cells…, Number tab.
              Select the Custom category.
              Enter mmm in the Type box.
              Click OK

            • #735682

              Format|Cells|Category:Custom|Type:mmm

            • #735683

              Format|Cells|Category:Custom|Type:mmm

          • #735185

            OK, but that doesn’t help. I want to display the month as 3 letters (Oct, Jan, etc.). If I format the day column as dd, it displays the date (26, 27, etc.); if I format it as ddd, it displays the day of the week (Mon, Tue, etc.). How do I get the month to display as 3 letters?

        • #735055

          The value in the cells in C are correct. You have them formatted as “mmm”

          The month is 10 (c11) for cell A11. You formatted the value 10 to “mmm” so it formats it as a date and the 10th day is Jan 10,1900 so displayed as “mmm” it is Jan.

          You can display a11 as “mmm” and it will display Oct. so instead of month(a11) just use = A11 and format as “mmm”

          Steve

      • #735007

        If the cell containing the date is formatted as general, it displays the date in serial number format. See the file dates.xls I have posted.

    • #734773

      If you format cell A1 as “general” what does it display?

      Steve

    Viewing 5 reply threads
    Reply To: Excel weirdness (2002 SP2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: