ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Using the DATEDIF, NETWORKDAYS, MONTH, YEAR and TODAY() functions in Excel 2007

Updated on September 28, 2012

Introduction

Welcome to my latest hub on Excel 2007. Today I will be investigating using dates in Excel 2007. Specifically, I will be showing how to get Excel to display today’s date in a cell and also to calculate the duration in days, months or years between two dates using a number of different functions.

This hub came about when I thought it would be cool if I could get Excel 2007 to calculate the number of hits my hubs receive per day. I had three variables I needed to obtain to calculate this, the total number of hits, today’s date and the number of days my hubs have been published. I only had one of those variables to hand which is the total number of hits. So I set about discovering how Excel could help me with this problem. I began with learning about the function TODAY ().

Using TODAY() in Excel 2007

The TODAY() function can be used in two ways. First, it can be used on its own to display the current date in a cell in Excel. It can also be used in formulas for date calculations. It is a very simple function, it has no arguments and can only be used as TODAY().

NOTE: When using the function in a formula, Excel stores the result as a date by default. To change this to a number, right click on the cell and select Format Cells and change Category to Number.

To get Excel to display today’s date in a cell, simply type in =TODAY() and press return.

Using TODAY() in a formula

If you need to know the number of days since something has occurred, for example the number of days since your birthday, or in my example the number of days a hub has been published, you should use the TODAY() function. The syntax is very straight forward as you can see below.

Using TODAY() in a formula in Excel 2007.
Using TODAY() in a formula in Excel 2007. | Source

Once you press enter, you will notice that the result is a series of #### as below. This is due to the formatting being set to Date. Change it to Number as outlined above and the correct result is displayed.

The results of using TODAY() in a formula will display as ##### until formated as a number in Excel 2007.
The results of using TODAY() in a formula will display as ##### until formated as a number in Excel 2007. | Source

Using the DATEDIF function in Excel 2007

While using TODAY() is perfect if you just want to know how many days have passed since a specific event, DATEDIF allows you to calculate using months and also years. To use the DATEIF formula in Excel 2007, you have to use the following syntax

=DATEDIF(<Start Date>,<End Date>,<Days, complete months or complete years (expressed as “D”,”M” or “Y”)>

The final argument can also contain combinations of years, days and months. For example,

MD – Excel returns the number of days between two dates while assuming that the dates were in the same month and year.

YD - Excel returns the number of days between two dates while assuming that the dates were in the same year.

YM - Excel returns the number of months between two dates while assuming that the dates were in the same year.

An example of the formula in use is shown below

An example of the DATEDIF function in Excel 2007.
An example of the DATEDIF function in Excel 2007. | Source

As previously mentioned, ensure that the cell containing your formula is formatted as a number rather than a date so that the cell’s contents display correctly.

NOTE: The final argument, M, D or Y (or one of the other combinations) must be in speech marks “M”, “D” or “Y” or Excel 2007 will return an error.

Other useful date related Excel 2007 functions

There are a number of other functions that are similarly useful when working with dates in Excel 2007.

NETWORKDAYS

The first of these is NETWORKDAYS. This will calculate the number of working or business days between two dates. There is also an option of including a list of holidays in a range that Excel 2007 will subtract from the number of workdays. An example of the syntax is below

=NETWORKDAYS(G47,TODAY())

If I add some holidays as you can see below, I add in a final argument to include the range of holidays.

Examples of the NETWORKDAYS function in Excel 2007.
Examples of the NETWORKDAYS function in Excel 2007. | Source
Examples of the NETWORKDAYS function in Excel 2007.
Examples of the NETWORKDAYS function in Excel 2007. | Source

You can see that Excel gives the total as 78 when including my (made up) holidays and 80 without.

MONTH

Another way of working out the number of months that have passed between two dates is to use the MONTH function. So I want to work out the number of months between the 6/11/2012 and today (note that the months are in the same year, if they are not use the formula in the next section). The formula I use for this is below.

Example of the MONTH function in Excel 2007.
Example of the MONTH function in Excel 2007. | Source

Formula for dates in different years

If you are calculating the number of months that have passed between two dates that are in a different year, the formula changes. You add in the following to the front of the formula

=(YEAR(TODAY())-YEAR(G47))*12+

Which becomes the following formula

=(YEAR(TODAY())-YEAR(G47))*12+MONTH(TODAY())-MONTH(G47)

NOTE: Again, note that YEAR occurs twice, just as MONTH has to.

NOTE: When working with this formula ensure that you use MONTH before your second date to ensure you don’t get a strange answer. If I leave out that second MONTH, Excel helpfully gives me the answer -41062 rather than the correct answer which is of course 3.

YEAR

To determine the number of years between two dates, use the YEAR function as we did for determining the number of months between dates in different years.

=YEAR(<End Date>)-YEAR(<Start Date>)

A Real life example of using dates in formulas

So, to finish off this hub on using dates, back to the original reason for my researching this in the first place. I wanted to calculate the number of hits per day that my hubs generate. To calculate the number of days since a hub was published, I used the following formula

An example of the DATEDIF and TODAY() functions in a formula in Excel 2007.
An example of the DATEDIF and TODAY() functions in a formula in Excel 2007. | Source

Now I have all the variables I need, so I simply divide the total number of hits by the number of days published and voila!

Conclusion

Excel 2007 has a number of very useful functions for determining the number of days, years or months that have passed between two dates. You have the MONTH and YEAR function which simply calculate months or years, as well as the more powerful DATEIF which allows you more flexibility. The NETWORKDAYS function allows you to calculate the number of working days between two dates and even allows you to adjust for holidays. Finally, the TODAY() function allows you to use today’s date in formulas.

I do hope that you have enjoyed reading this hub as much as I enjoyed writing it. Please feel free to leave any comments you may have below.

I also have a number of other hubs on aspects of Excel 2007, covering everything from Conditional Formatting to creating charts and graphs. I have an Index hub which also covers how I successfully transitioned from Excel 2003 to 2007 as well as outlining my other Excel 2007 hubs which can be found here

http://robbiecwilson.hubpages.com/hub/How-to-adjust-to-Excel-2007-from-previous-versions-as-well-as-step-by-step-guides-to-many-functions-in-Excel-2007

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)