DateDiff: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
(Created page with "DATEDIFF(''interval'', ''date1'', ''date2''[, ''firstdayofweek''[, ''firstweekofyear'']]) '''Description''' DATEDIFF returns the number of intervals between two dates. The r...")
 
No edit summary
Line 1: Line 1:
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 Table 6.. 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.
DateDiff returns the number of intervals between two dates. The required parameter, ''interval'', is a string expression, see Table 6.. 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.


'''Table 7: firstdayofweek constants'''
'''Table 7: firstdayofweek constants'''
Line 32: Line 32:
{| class="wikitable"
{| class="wikitable"
|-
|-
! Header text !! Header text !! Header text
! Constant !! Value !! Description
|-
|-
| vbUseSystem || 0 || NLS API setting
| vbUseSystem || 0 || NLS API setting
Line 43: Line 43:
|}
|}


'''Example'''
== Example ==


<pre>
<pre>
REM DATEDIFF Example
REM DateDiff Example
'DATEDIFF calc difference between 2 dates
'DateDiff calc difference between 2 dates
DIM Born
DIM Born
Born = INPUTBOX("Enter your birthdate")
Born = InputBox("Enter your birthdate")
Born = CDATE(Born)
Born = CDate(Born)
PRINT "Since " & Born & " there have been"
PRINT "Since " & Born & " there have been"
PRINT DATEDIFF("d", Born, NOW) & " days"
PRINT DateDiff("d", Born, NOW) & " days"
PRINT "or"
PRINT "or"
PRINT DATEDIFF("n", Born, NOW) & " minutes"
PRINT DateDiff("n", Born, NOW) & " minutes"
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 67: Line 67:
</pre>
</pre>


'''Related Items'''
== Related Items ==


[[dateadd|DATEADD]], [[datepart|DATEPART]]
[[dateadd|DATEADD]], [[datepart|DATEPART]]
[[Category:Language Reference]]

Revision as of 20:39, 8 August 2012

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 6.. 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.

Table 7: 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

Table 8: 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

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'')

Related Items

DATEADD, DATEPART