So the last function that I want to talk about in this section is called Date def and it calculates
the number of days months or years between two given dates.
So three components of the formula syntax starts with a start date.
Then you can put an end date.
The third piece is the unit.
So this is determining how you want to calculate the difference between the two days.
You can set it here to calculate it as the number of days between the dates and would return the number
of months between dates.
Why would return the number of years between dates.
There are also options like M.D Y.D. or Y and which will calculate these differences regardless of months
or regardless of years.
So two examples here.
Again we're looking at the same start and end dates that we used in the previous two examples.
January 1st 2015 or start February 28 2015 is our.
And so if we set the date diff between our start date and B to end date and B 3 and set the unit 2 days
it will return 58 since there are 58 days between these dates.
And note that this is functioning kind of like a network day's function except the network days is excluding
weekends.
This is returning all of the dates.
And also note that this is doing the exact same thing as just writing the formula be 3 minus 2.
So protip if you only need to calculate the number of days between dates just use simple subtraction
you don't need to use a date if function for that but where the date function becomes much more valuable
and where it cant be replicated using simple operations is if you want to calculate the difference in
terms of months or years or so on and so forth.
So if we want to say date def between January 1st and February 28 with the M.D unit which is the number
of days between dates ignoring months and years its going to say there are 27 days between the 28 and
the first regardless if I am looking at a different month or different year.
So lets take a look at Excel and practice this.
So to revisit this project due date that we had written in the last lecture what I can do here is if
I want to calculate the months remaining until my project is due I can type equals date def and then
I dont know why this is the case but Excel doesnt help you through this function it just kind of leaves
you hanging.
Not sure if its a bug or what but if we rely on our memory we know that the first component of the date
is the start date which is my current date and then the end date is going to be that due date and then
the last piece is the unit remember.
So in this case any of the months remaining so we put an end in quotes and this wont work unless I put
them in quotes here.
So just keep that in mind and then when I hit enter that tells me that I have 20 months remaining from
the current date through the date that my project is due.
And thats similar case here.
What I'll do instead of writing this from scratch I'm just going to fix the references in my original
functions or fix the C to and fix the F3.
Copy that formula.
Paste it down and change the end to a Y.
Since I want the years remaining.
So it's telling me that I have one year remaining until my project is due.
I could also jump back to sell 5 where I'd calculated my days until do as just three months see two
and let's see if we can get the same answer six hundred thirty using a date function.
So I'm going to do date def C-2 comma after the comma D in quotes.
And there you go Sixthly.
So again it two ways to do the same thing.
And I don't know about you but I would prefer just say F three minus two and call it a day.
But date def can be a great option especially if you want to aggravate the difference between two dates
at the month or year level.