Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>(This solution is in PHP -- but you can probably do that directly from the command-line, I suppose, with somekind of grep or anything)</em></p> <p>Considering your dates are in the <code>YYYY-MM-DD</code> format, and that they are at the beginning of each line, you just have to compare the lines alphabetically to compare the dates.</p> <p>One solution would be to :</p> <ul> <li>load the string</li> <li>explode it by lines</li> <li>remove the first line</li> <li>iterate over the lines, keeping only those that interest you</li> </ul> <p>For the first parts :</p> <pre><code>$str = &lt;&lt;&lt;STR date,test,time,avail 2009-09-01,JS,0.119,99.90 2009-09-02,JS,0.154,99.89 2009-09-03,SWF,0.177,99.90 2009-09-04,SWF,0.177,99.90 2009-09-05,SWF,0.177,99.90 2009-09-06,SWF,0.177,99.90 2009-09-07,SWF,0.177,99.90 2009-09-08,SWF,0.177,99.90 2009-09-09,SWF,0.177,99.90 2009-09-10,SWF,0.177,99.90 STR; $lines = explode(PHP_EOL, $str); unset($lines[0]); // first line is useless </code></pre> <p>And, to iterate over the lines, filtering in/out those you want / don't want, you could use a foreach loop... Or use the <a href="http://php.net/array_filter" rel="nofollow noreferrer"><code>array_filter</code></a> function, which exists just for this ;-)</p> <p>For instance, you could use something like this :</p> <pre><code>$new_lines = array_filter($lines, 'my_filter'); var_dump($new_lines); </code></pre> <p>And your callback function would be :</p> <pre><code>function my_filter($line) { $min = '2009-09-04'; $max = '2009-09-09'; if ($line &gt;= $min &amp;&amp; $line &lt;= $max) { return true; } else { return false; } } </code></pre> <p>And, the result :</p> <pre><code>array 4 =&gt; string '2009-09-04,SWF,0.177,99.90' (length=26) 5 =&gt; string '2009-09-05,SWF,0.177,99.90' (length=26) 6 =&gt; string '2009-09-06,SWF,0.177,99.90' (length=26) 7 =&gt; string '2009-09-07,SWF,0.177,99.90' (length=26) 8 =&gt; string '2009-09-08,SWF,0.177,99.90' (length=26) </code></pre> <p>Hope this helps ;-)</p> <p><br> If your dates where not in the <code>YYYY-MM-DD</code> format, or not at the beginning of each line, you'd have to <a href="http://php.net/explode" rel="nofollow noreferrer"><code>explode</code></a> the lines, and use <a href="http://php.net/strtotime" rel="nofollow noreferrer"><code>strtotime</code></a> <em>(or do some custom parsing, depending on the format)</em>, and, then, compare timestamps.</p> <p>But, in your case... No need for all that ;-)</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