Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've been using MySQL and it work fine. Just recently I change to SQLite. But I am having problem with to_days(now()) function. Is it that SQLite dosen't support this function? or I just miss something?

Replies are listed 'Best First'.
Re: to_days(now())
by superfrink (Curate) on Jan 16, 2005 at 02:53 UTC
    In the future it might help to post the code you are having trouble with. Also questions about SQLite might get better replies if posted to the SQLite mailing list. Anyway I get errors when I call NOW() or TO_DAYS().
    $sql = "SELECT NOW()"; $sth = $dbh->prepare($sql) or die "Error:" . $dbh->errstr . "\n"; $sth->execute() or die "Error:" . $sth->errstr . "\n"; while(my $row = $sth->fetchrow_hashref) { print Dumper($row); }
    produces:
    Error:no such function: NOW(1) at dbdimp.c line 263

    The docs for DBD::SQLite describe creating a NOW() function via:
    $dbh->func( 'now', 0, sub { return time }, 'create_function' );
      $sql_stmt = qq~ delete from session where (((to_days(now()) * $day_minute) + (hour(now()) * $hour_ +minute) + minute(now())) - ((to_days(last_req) * $day_minute) + (hour(last_req) * $hour_m +inute) + minute(last_req))) > $session_limit~; $sth = $dbh->prepare($sql_stmt); $sth->execute() or &error("1SQL&Couldn't execute statement: $D +BI::errstr"); $sth->finish();
      I read from CPAN, but I am confuse how to implement it. Can some one show how to do that with my code.
Re: to_days(now())
by meredith (Friar) on Jan 16, 2005 at 06:28 UTC

    The function you want is julianday(). More specifically, julianday('now'). See here for an example where I translated some statements from MySQL to SQLite.

    mhoward - at - hattmoward.org