Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl and MYSQL - Select data between year-month-day hour:minute:seconds (unix?) style timestamps
    text
    copied!<p>I have looked all day for an answer and tried all my thoughts as well. What I am doing is seemingly easy but, VERY difficult for me. I must do this without installing additional Perl Modules.</p> <p>I am trying to select a list of names that were entered between two dates. I know these examples are obviously not strict or safe but, I am just trying to figure out. I will fix all that later once I get the means to my required result figured out.</p> <p>The incoming data example for the $to and $from:</p> <pre><code>$to= '2013-03-01 00:00:01'; $from= '2013-03-01 23:23:59'; </code></pre> <p>The <code>entered</code> column in the database is in that format as well.</p> <p>I tried:</p> <pre><code>$names = DBI-&gt;connect("$sdb","$user","$password"); $getnames = $names-&gt;prepare(qq{SELECT DISTINCT `name` FROM `users` WHERE `entered` BETWEEN UNIX_TIMESTAMP($from) AND UNIX_TIMESTAMP($to) AND `active` = ? AND `confirmed` = ? ORDER BY `entered` DESC}); $getnames-&gt;execute($active,$confirmed); </code></pre> <p>And I tried: </p> <pre><code> $names = DBI-&gt;connect("$sdb","$user","$password"); $getnames = $names-&gt;prepare(qq{SELECT DISTINCT `name` FROM `users` WHERE `entered` BETWEEN ? AND ? AND `active` = ? AND `confirmed` = ? ORDER BY `entered` DESC}); $getnames-&gt;execute($from,$to,$active,$confirmed); </code></pre> <p>I also tried many variations of the above two but, I keep getting:</p> <pre><code>Can't call method "prepare" on an undefined value at users-by-date.pl line 120 even when I hard code the variables. </code></pre> <p>Can someone show me how to do this? My query executes fine in phpmyadmin but, I need the result printed to a page using Perl. I believe it has something to do with the dates format. NO, I cannot change the dates format in the database.</p> <p>Thanks so much.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload