Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

How to search database by date range

by kingmx (Initiate)
on May 09, 2013 at 10:39 UTC ( #1032758=perlquestion: print w/ replies, xml ) Need Help??
kingmx has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone know how to search database by date range?

I'm using Perl Catalyst framework and I want to produce a query like this.

SELECT * FROM table WHERE date BETWEEN 2013-05-03 AND 2013-05-04;

Here's my code and I'm stuck on thinking how to write the "where" clause.

my $rs = [$c->model('DB::table')->search( { 'me.date' => ???? } ,{} )];

Thanks. :)

Comment on How to search database by date range
Select or Download Code
Re: How to search database by date range
by Anonymous Monk on May 09, 2013 at 11:02 UTC

    I'm using Perl Catalyst framework and I want to produce a query like this.

    Catalyst comes with many classes/plugins.... so which one are you using? What is your model class?

Re: How to search database by date range
by ww (Bishop) on May 09, 2013 at 11:15 UTC
    It might also be helpful to tell us WHICH database.

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: How to search database by date range
by thundergnat (Deacon) on May 09, 2013 at 15:42 UTC

    It probably will be something like:

    my $rs = [$c->model('DB::table')->search( { 'me.date' => { between => ['2013-05-03', '2013-05-04'] } } ,{} )];

    Check the SQL::Abstract docs for the gritty details.

Re: How to search database by date range
by tobyink (Abbot) on May 09, 2013 at 15:53 UTC

    FWIW, just because you're using Catalyst, there's no law that compels you to use DBIx::Class too.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

      Wow, thank you guys for the replies.

      I solved the problem with this code.

      my $rs = [$c->model('DB::table')->search( { 'me.date' => { "<=" => "2013-05-04", ">=" => "2013-05-03" } } ,{} )];

      To ww:
      sorry if I didn't put the actual codes. The reason is, I just want to limit my question to what I really needed.

      To thundergnat:
      Thanks for the link! I find it very informative. I will also try your suggestion.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032758]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-12-29 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls