interval()

Read(5573) Label: interval, datetime value,

Description:

Compute the number of days between two datetime values.

Syntax:

interval (t1,t2)

t1- t2    Equivalent to interval (t2, t1)

Note:

The function computes the number of days between two datetime values t1 and t2.

Parameter:

t1

A date value, datetime value or integer; when it is an integer, it can be understood as value of days@o().

t2

A date value, datetime value or integer; when it is an integer, it can be understood as value of days@o().

Option:

@y

Compute the number of years between two datetime values.

@q

Compute the number of quarters between two datetime values.

@m

Compute the number of months between two datetime values.

@s

Compute the number of seconds between two datetime values.

@ms

Compute the number of milliseconds between two datetime values.

@w

Compute the number of weeks between two datetime values.

@7

Compute the number of Sundays between two datetime values according to a left-open interval.

@1

Compute the number of Mondays between two datetime values according to a left-open interval.

@r

Work with options @y, @m and @w. Add the duration less than a whole day to the number of whole days as a fractional part; the interval of datetime values is left-open and right-closed.

@ymd

Return result as an integer in the form of ymmdd according to a left-open and right-closed interval.

@ym

Return result as an integer in the form of ymm according to a left-open and right-closed interval.

@md

Return result as an integer in the form of mdd according to a left-open and right-closed interval.

@yd

Return result as an integer in the form of yddd according to a left-open and right-closed interval.

@wy(t1)

Compute the number of weeks between t1 and the first day of the year in which t1 falls.

@wq(t1)

Compute the number of weeks between t1 and the first day of the quarter in which t1 falls.

@wm(t1)

Compute the number of weeks between t1 and the first day of the month in which t1 falls.

@7y(t1)

Compute the number of Sundays between t1 and the first day of the year in which t1 falls.

@7q(t1)

Compute the number of Sundays between t1 and the first day of the quarter in which t1 falls.

@7m(t1)

Compute the number of Sundays between t1 and the first day of the month in which t1 falls.

@1y(t1)

Compute the number of Mondays between t1 and the first day of the year in which t1 falls.

@1q(t1)

Compute the number of Mondays between t1 and the first day of the quarter in which t1 falls.

@1m(t1)

Compute the number of Mondays between t1 and the first day of the month in which t1 falls.

Return value:

Integer

Example:

interval(datetime("19800227","yyyyMMdd"),datetime("1983-02-27 00:00:45"))

1097

interval@y(datetime("19800227","yyyyMMdd"),datetime("1983-02-27 00:00:45"))

3

interval@q(datetime("19800227","yyyyMMdd"),datetime("1983-02-27 00:00:45"))

12

interval@m(datetime("19800227","yyyyMMdd"),datetime("1983-02-27 00:00:45"))

36

interval@s(datetime("19800227","yyyyMMdd"),datetime("1980-02-27 00:00:45"))

45

interval@s ("1972-11-08 10:20:30","1972-11-08 10:30:50")

620

interval@ms(datetime("19800227","yyyyMMdd"),datetime("1980-02-27 00:00:45"))

45,000

interval@ms("1972-11-08 10:20:30","1972-11-08 10:30:50")

620,000

interval@r(datetime("19800227","yyyyMMdd"),datetime("1980-02-27 00:00:45"))

5.208333333333333E-4

interval@r("1972-11-08 10:20:30","1973-11-08 10:30:50")

365.00717592592594

datetime("19850227","yyyyMMdd")-datetime("1983-02-27 00:00:45")

730

interval@w("1972-10-08 10:20:30","1972-11-08 10:30:50")

4

interval@7("1972-10-08 10:20:30","1972-11-08 10:30:50")

4

interval@1("1972-10-08 10:20:30","1972-11-08 10:30:50")

5

interval@y(15899,23545)

20

interval@y(date@o(15899),date@o(23545))

20

interval@ry("2023-11-26","2024-12-05")

1.0273972602739727

interval@rm("2023-11-26","2024-12-05")

12.5

interval@rw("2023-11-26","2024-12-05")

53.57142857142857

interval@ymd("2021-07-26","2024-12-05")

30409

interval@ym("2021-07-26","2024-12-05")

304

interval@yd("2021-07-26","2024-12-05")

3132

interval@md("2021-07-26","2024-12-05")

4009

interval@wy("2026-04-26")

16

interval@wq("2026-04-26")

3

interval@wm("2026-04-26")

3

interval@7y("2026-04-26")

17

interval@7q("2026-04-26")

4

interval@7m("2026-04-26")

4

interval@1y("2026-04-26")

16

interval@1q("2026-04-26")

3

interval@1m("2026-04-26")

3