Date Manipulation Part 3 : Find the amount of time between dates with DateDiff()Part 1 |
Part 2 |
Part 3 |
Part 4
Find out how much time occurs between two dates is easy with DateDiff(). This function is useful if you
need to find the amount of time between one date and another, or if you need to find out how much time
is left until the end of the year.

DateDiff(PartOfDate, Date1, Date2[, FirstDayOfWeek, FirstDayOfYear])
- returns the amount of time in between the two dates in the form of PartOfDate, therefore if you set
PartOfDate equal to year, the function will tell you how many years are in between Date1 and Date2
even if you are comparing Dec 31 and Jan 1. If you set PartOfDate equal to day then the function
will return to you the number of days between Date1 and Date2.
- if Date1 occurs after Date2 the function will return to you a negative number.
- optional parameters are setting the first day of the week (defaults to Sunday), and setting the
first week of the year (defaults to Jan 1).

FirstDayOfYear optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Start with the week that has Jan 1 in it (the default value if this parameter is not supplied)
2 - Start with the first week that contains at least four days in the new year.
3 - Start with the first week that is a full week in the new year.

- I recommend just leaving the two optional parameters out unless they specifically apply
to what you are currently trying to do.