Determine The Amount Time Between Dates

You can determine the amount of time between two different dates by using the DateDiff function. With this function you can return almost any time interval between the specified date values, such as months, days, hours, minutes, or even seconds.

The DateDiff function has five different arguments of which the first three are required: Interval, Datel, Date2, Firstdayofweek, and Firstweekofyear.

You can use the Interval argument to express, in units of time, the difference between the two dates. There are ten different values that you can specify for this argument.

The Date1 and Date2 arguments specify the two dates you want to compare. You can use a date string, the value returned by a function, or the contents of a cell, as long as it is a valid date. To ensure the date is valid, consider using the IsDate function to check the date.

DETERMINE THE AMOUNT OF TIME BETWEEN DATES

You can utilize the optional Firstdayofweek argument if you want to use a day other than Sunday as the first day of the week. To specify a constant value for this argument, you simply include vb before the appropriate day of the week. For example, to use Monday as the first day of the week, you specify vbMonday as the value of the argument. See Appendix A for Firstdayofweek constant values.

Finally, you can use the optional Firstweekofyear argument to indicate what you want to treat as the first week of the year. If you omit this argument, VBA considers the first week that contains the date January 1 as the first week of the year, even if it falls on Saturday. For example, If you want to have the first week containing at least four days of January, you specify a value of vbFirstFourDays. See Appendix A for Firstweekofyear constant values.

DETERMINE THE AMOUNT OF TIME BETWEEN DATES

□ Create a new subroutine.

< Type Dim Date2 As Variant, replacing Date2 with the variable for the second date.

0 Type initial VBA code.

Q Type Date2 = datevalue2, replacing Date2 with the variable in step 3 and datevalue2 with the second date.

□ Create a new subroutine.

Type Dim Date1 As Variant, replacing Datel with the variable for the first date.

< Type Dim Date2 As Variant, replacing Date2 with the variable for the second date.

0 Type initial VBA code.

^0 Type Date1 = datevalue'l, replacing Datei with the variable in step 2 and datevaluei with the first date.

Q Type Date2 = datevalue2, replacing Date2 with the variable in step 3 and datevalue2 with the second date.

0 0

Post a comment