DateDiff: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
''This function is for BASIC compatibility. It is not available in pure JavaScript projects.'' | |||
DateDiff(''interval'', ''date1'', ''date2''[, ''firstdayofweek''[, ''firstweekofyear'']]) | DateDiff(''interval'', ''date1'', ''date2''[, ''firstdayofweek''[, ''firstweekofyear'']]) | ||
== Description == | == Description == | ||
DateDiff returns the number of intervals between two dates. The required parameter, ''interval'', is a string expression: see | DateDiff returns the number of intervals between two dates. The required parameter, ''interval'', is a string expression: see table below. The required parameters, ''date1'' and ''date2'', can be any expressions that represent dates. The optional parameter ''firstdayofweek'' is Sunday, if not specified. The optional ''firstweekofyear'' is the week containing January 1, if not specified. | ||
''' | '''Interval Values''' | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 32: | Line 34: | ||
|} | |} | ||
''' | '''firstdayofweek constants''' | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 55: | Line 57: | ||
|} | |} | ||
''' | '''firstweekofyear constants''' | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 70: | Line 72: | ||
|} | |} | ||
== Example == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 101: | Line 103: | ||
[[Category:Date and Time]] | [[Category:Date and Time]] | ||
[[Category:BASIC Functions]] |
Latest revision as of 15:21, 25 March 2019
This function is for BASIC compatibility. It is not available in pure JavaScript projects.
DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
Description
DateDiff returns the number of intervals between two dates. The required parameter, interval, is a string expression: see table below. The required parameters, date1 and date2, can be any expressions that represent dates. The optional parameter firstdayofweek is Sunday, if not specified. The optional firstweekofyear is the week containing January 1, if not specified.
Interval Values
Value | Description |
---|---|
yyyy | Year |
q | Quarter |
m | Month |
y | Day of year |
d | Day |
w | Weekday |
ww | Week of year |
h | Hour |
n | Minute |
s | Second |
firstdayofweek constants
Constant | Value | Description |
---|---|---|
vbUseSystem | 0 | NLS API setting |
vbSunday | 1 | Sunday |
vbMonday | 2 | Monday |
vbTuesday | 3 | Tuesday |
vbWednesday | 4 | Wednesday |
vbThursday | 5 | Thursday |
vbFriday | 6 | Friday |
vbSaturday | 7 | Saturday |
firstweekofyear constants
Constant | Value | Description |
---|---|---|
vbUseSystem | 0 | NLS API setting |
vbFirstJan1 | 1 | Week with January 1 |
vbFirstFourDays | 2 | First week of year with at least 4 days |
vbFirstFulWeek | 3 | First full week of year |
Example (Basic)
Rem DateDiff Example 'DateDiff calc difference between 2 dates Dim Born Born = InputBox("Enter your birthdate") Born = CDate(Born) Print "Since " & Born & " there have been" Print DateDiff("d", Born, Now) & " days" Print "or" Print DateDiff("n", Born, Now) & " minutes"
Output
Since 12/27/1970 there have been 10096 days or 14539612 minutes (''sample date output is system dependant'')