DateDiff Function

Returns the number of date or time intervals between two given date values.

Syntax:


DateDiff (interval As String, date1 As Date, date2 As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Double

āĻĒā§āĻ°āĻĻāĻžāĻ¨ āĻŽāĻžāĻ¨:

āĻāĻ•āĻŸāĻŋ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻžāĨ¤

Parameters:

interval - A string expression from the following table, specifying the date or time interval.

interval (string value)

āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž

yyyy

āĻŦāĻ›āĻ°

q

āĻšāĻ¤ā§āĻ°ā§āĻĨāĻžāĻ‚āĻļ

m

āĻŽāĻžāĻ¸

y

āĻŦāĻ›āĻ°ā§‡āĻ° āĻĻāĻŋāĻ¨

w

āĻ•āĻ°ā§āĻŽāĻĻāĻŋāĻŦāĻ¸

ww

āĻŦāĻ›āĻ°ā§‡āĻ° āĻ¸āĻĒā§āĻ¤āĻžāĻš

d

āĻĻāĻŋāĻ¨

h

āĻ˜āĻ¨ā§āĻŸāĻž

n

āĻŽāĻŋāĻ¨āĻŋāĻŸ

s

āĻ¸ā§‡āĻ•ā§‡āĻ¨ā§āĻĄ


date1, date2 - The two date values to be compared.

Date literals allow to specify unambiguous date variables that are independent from the current language. Literals are enclosed between hash signs #. Possible formats are:

firstdayofweek: An optional parameter that specifies the starting day of a week.

firstdayofweek value

āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž

0

āĻ¸āĻŋāĻ¸ā§āĻŸā§‡āĻŽā§‡āĻ° āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ āĻŽāĻžāĻ¨ āĻŦā§āĻ¯āĻŦāĻšā§ƒāĻ¤ āĻšā§Ÿ

1

āĻ°āĻŦāĻŋāĻŦāĻžāĻ° (āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ)

2

āĻ¸ā§‹āĻŽāĻŦāĻžāĻ°

3

āĻŽāĻ™ā§āĻ—āĻ˛āĻŦāĻžāĻ°

4

āĻŦā§āĻ§āĻŦāĻžāĻ°

5

āĻŦā§ƒāĻšāĻ¸ā§āĻĒāĻ¤āĻŋāĻŦāĻžāĻ°

6

āĻļā§āĻ•ā§āĻ°āĻŦāĻžāĻ°

7

āĻļāĻ¨āĻŋāĻŦāĻžāĻ°


firstweekofyear: An optional parameter that specifies the starting week of a year.

firstweekofyear value

āĻŦā§āĻ¯āĻžāĻ–ā§āĻ¯āĻž

0

āĻ¸āĻŋāĻ¸ā§āĻŸā§‡āĻŽā§‡āĻ° āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ āĻŽāĻžāĻ¨ āĻŦā§āĻ¯āĻŦāĻšā§ƒāĻ¤ āĻšā§Ÿ

1

āĻŦāĻ›āĻ°ā§‡āĻ° ā§§āĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻšāĻŸāĻŋ āĻšāĻ˛ā§‹ ā§§āĻ˛āĻž āĻœāĻžāĻ¨ā§ā§ŸāĻžāĻ°āĻŋ āĻ¸āĻŽā§āĻŦāĻ˛āĻŋāĻ¤ āĻ¸āĻĒā§āĻ¤āĻžāĻš (āĻĄāĻŋāĻĢāĻ˛ā§āĻŸ)

2

āĻ¸āĻĒā§āĻ¤āĻžāĻš ā§§ āĻšāĻ˛ā§‹ āĻ¸ā§‡āĻ‡ āĻŦāĻ›āĻ°ā§‡āĻ° āĻšāĻžāĻ° āĻ…āĻĨāĻŦāĻž āĻ¤āĻ¤ā§‹āĻ§āĻŋāĻ• āĻĻāĻŋāĻ¨ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻŸ āĻĒā§āĻ°āĻĨāĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻš

3

āĻ¸āĻĒā§āĻ¤āĻžāĻš ā§§ āĻšāĻ˛ā§‹ āĻ¨āĻ¤ā§āĻ¨ āĻŦāĻ›āĻ°ā§‡āĻ° āĻļā§āĻ§ā§āĻŽāĻžāĻ¤ā§āĻ° āĻĻāĻŋāĻ¨ āĻŦāĻŋāĻļāĻŋāĻˇā§āĻŸ āĻĒā§āĻ°āĻĨāĻŽ āĻ¸āĻĒā§āĻ¤āĻžāĻš


Example:


Sub example_datediff
    MsgBox DateDiff("d", #1/1/2005#, #2005-12-31#)
End Sub

Please support us!