2013-03-19 74 views
1

我正试图返回今天的生日。这就是我现在所拥有的,这是有效的,但我需要抓住月份和日子来输入声明。我想也许我可以从当地时间抓住他们,但那并没有奏效。任何建议,将不胜感激。DBIx :: Class和搜索

sub author_birth { 
    my ($self) = @_; 
    my ($day,$month) = (localtime())[3..4]; 
    my $author_result = $self->search_like(
     { 
      birth => '%03-20' 
     }, 
     { 
      select => [ 
       'id', 
       'complete_name', 
      ], 

      #result_class => 'DBIx::Class::ResultClass::HashRefInflator' 
     } 
    ); 

    my @author_ids =(); 
    while (my $row = $author_result->next) { 
     push @author_ids, $row->id; 
    } 

    return $self->get_author_info_by_id(\@author_ids); 

} 
+0

它不适用于'$ day'和'$ month',因为它们不包含数据库中日期包含的前导零。最好的解决方案(你似乎已经制定出来)是使用Time :: Piece。 – 2013-03-20 09:59:42

+0

感谢您的解释,直到昨天我才意识到Time :: Piece。干杯。 – 2013-03-20 16:09:57

回答

2

我最终做了这样的事情。

my ($self) = @_; 
my $conc = '%'; 
my $datetime = Time::Piece->new->strftime('%m-%d'); 
my $date = $conc . $datetime; 
my $author_result = $self->search_like(
    { 
     birth => $date, 
    }, 
    { 
     select => [ 
      'id', 
      'complete_name', 
     ], 

     #result_class => 'DBIx::Class::ResultClass::HashRefInflator' 
    } 
); 
相关问题