Filter_Expression as C = between_date(C field ,D date1 ,D date2 )



A character filter expression that evaluates to a logical value and selects records from a table.


The name of a field that you wish to write a filter expression against. Character


Date. A date variable or value that contains the first or lowest value to include in the filter.


Date. A date variable or value that contains the last or highest value to include in the filter.


Creates a string using the Between() function


BETWEEN_DATE() returns a character filter expression that uses the two date values and selects records from the table. This function is only useful in Xbasic scripts. Field_Name is a date field or expression to search on. Low_Value and High_Value are date variables. They are the first and last values in a range of records to find. Frequently in Xbasic scripts, you need to specify a filter expression in quotes. It can get quite tricky to do this if your Low_Value and High_Value values are stored in variables. For example, the following code fragment shows how to specify a filter expression for an Xbasic query:

dim shared First as D
dim shared Last as D
dim t as P
dim i as P
first = {01/01/1900}
last = {12/31/2003}
t = table.open("invoice_header")
query.filter = between_date("date", first, last)
i = t.query_create()
? query.filter
= "between(date,{01/01/1900},{12/31/2003})"

query.filter will contain the following value:

"between(invoice_date, {1/1/2000}, {12/31/2000})"

This is a valid filter expression. However, it is very cumbersome to write the expression that defines the query.filter variable. The BETWEEN_DATE() utility function makes it easier to write this filter expression. For example:

query.filter = between_date("Invoice_Date", First,  Last)

If you are searching on fields/expressions of other types, use the appropriate utility function. Assuming that lastname, qty, and invoice_date are field names.

Field Type
Function and Example

BETWEEN_CHAR(): between_char("lastname", first, last)


BETWEEN_NUM(): between_num("qty", first, last)


BETWEEN_DATE(): between_date("invoice_date", first, last)

Record number

BETWEEN_RECORD(): between_record(first, last)


between_char("Lastname","Smith", "Jones")  -> "between(lastname, \"Smith\", \"Jones\")"
between_num("Qty", start, end) -> "between(qty,  3, 10)", assuming the start and end variables contain 3 and 10
between_date("Invoice_Date", start, end)  -> "between(invoice_date, {1/1/2000}, {12/31/2000})",  assuming the start and end variables contain {1/1/2000} and {12/31/2000}.
between_record(start, end) -> "between(recno() , 3,  10)", assuming the start and end variables contain 3 and 10  'The following example shows how these functions can be used in situations where a quoted filter string is expected:'(Note that since the function RETURNS a quoted string, it is not necessary to quote the value assigned to query.filter)query.filter = between_char("Lastname","Smith","Jones")query.order = "Lastname"dim tbl as p dim i as p tbl = table.open("customers")i = tbl.query_create()  startDate = {1/1/2007}endDate = {1/31/2008}query.filter = between_date("OrderDate",startDate,endDate)query.order = "OrderId"tbl = table.open("Orders")i = tbl.query_create()  

The following function determines the fiscal year of a date. The begin_date is the first day of the fiscal year.
FUNCTION fiscal_year as N (current_date as D,  begin_date as D )
fiscal_year = -1
if (alltrim(cdate(current_date) ) = "") .or. (alltrim(cdate(begin_date) )  = "") .or. (day(begin_date) > 1)
end if
    case month(begin_date) = 1
        fiscal_year  = year(current_date)
    case between(month(current_date),month(begin_date),12)
        fiscal_year  = year(curdate)
    case between(month(current_date),  1, month(begin_date)-1)
        fiscal_year  = year(current_date) - 1
end select

See Also