Date range and match specification syntax

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

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 = [
         [{'>=', 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 = [
              [{'>=', 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,
                             {shell,eval_loop,2}]} **

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


More information about the erlang-questions mailing list