Date range and match specification syntax

Massimo Cesaro massimo.cesaro@REDACTED
Tue Oct 7 13:17:01 CEST 2003


Hello,
I'm trying to select-ing from a mnesia table all the records inside a
date range. I see that Dates are {Year, Month, Day} tuples, hence this 
Query = [
         {'$1',
         [{'>=', StartDate, {element, 3, '$1'}}, {'=<', EndDate,
{element, 3, '$1'}}],
          ['$_']}],
    mnesia:dirty_select(cdr, Query).

will fail with a badarg because the >= operator cannot be applied on
tuples (well, I think this is the resons why the shell complains).

My second approach is using date_to_gregorian_days:
    Query = [
             {'$1',
              [{'>=', calendar:date_to_gregorian_days(StartDate),
calendar:date_to_gregorian_days({element, 3, '$1'})}],
              ['$_']}],
    mnesia:dirty_select(cdr, Query).

but this fails with 
** exited: {function_clause,[{calendar,
                                 date_to_gregorian_days,
                                 [element,3,'$1']},
                             {otr_cdr,get,2},
                             {erl_eval,expr,3},
                             {erl_eval,exprs,4},
                             {shell,eval_loop,2}]} **

Maybe I'm using a wrong approach; any suggestion on how to solve this
apparently simple problem ?

Massimo





More information about the erlang-questions mailing list