Page 280 - Excel 2007 Bible
P. 280

18_044039 ch13.qxp  11/21/06  11:05 AM  Page 237
                                             Determining the day of the year
                                             January 1 is the first day of the year, and December 31 is the last day. But what about all those days in
                                             between? The following formula returns the day of the year for a date stored in cell A1:
                                                 =A1-DATE(YEAR(A1),1,0)
                                             The following formula returns the number of days remaining in the year after a particular date (assumed to
                                             be in cell A1):
                                                 =DATE(YEAR(A1),12,31)-A1
                                             When you enter either of these formulas, Excel applies date formatting to the cell. You need to apply a non-
                                             date number format to view the result as a number.
                                             To convert a particular day of the year (for example, the 90th day of the year) to an actual date in a specified
                                             year, use the formula that follows. This formula assumes that the year is stored in cell A1 and the day of the
                                             year is stored in cell B1.
                                                 =DATE(A1,1,B1)
                                             Determining the day of the week                Working with Dates and Times     13
                                             The WEEKDAY function accepts a date argument and returns an integer between 1 and 7 that corresponds to
                                             the day of the week. The following formula, for example, returns 3 because the first day of the year 2008
                                             falls on a Tuesday:
                                                 =WEEKDAY(DATE(2008,1,1))
                                             The WEEKDAY function uses an optional second argument that specifies the day numbering system for the
                                             result. If you specify 2 as the second argument, the function returns 1 for Monday, 2 for Tuesday, and so on.
                                             If you specify 3 as the second argument, the function returns 0 for Monday, 1 for Tuesday, and so on.
                                           TIP         You can also determine the day of the week for a cell that contains a date by applying a cus-
                                           TIP
                                                       tom number format. A cell that uses the following custom number format displays the day of
                                            the week, spelled out:
                                               dddd
                                             Determining the date of the most recent Sunday
                                             You can use the following formula to return the date for the previous Sunday. If the current day is a Sunday,
                                             the formula returns the current date:
                                                 =TODAY()-MOD(TODAY()-1,7)
                                             To modify this formula to find the date of a day other than Sunday, change the 1 to a different number
                                             between 2 (for Monday) and 7 (for Saturday).
                                             Determining the first day of the week after a date
                                             This next formula returns the specified day of the week that occurs after a particular date. For example, use
                                             this formula to determine the date of the first Monday after June 1, 2007. The formula assumes that cell A1
                                             contains a date and cell A2 contains a number between 1 and 7 (1 for Sunday, 2 for Monday, and so on).
                                                 =A1+A2-WEEKDAY(A1)+(A2<WEEKDAY(A1))*7



                                                                                                                      237
   275   276   277   278   279   280   281   282   283   284   285