Listing random dates in earliest to newest order
<p>How do you go about listing random dates (from earliest to newest)? </p>

<p>I've been trying to accomplish this with PHP but with no success. I can get a random date to show up but keeps looping the same one over and over again rather than creating new ones and listing them in the order specified. </p>

<p>This is my code so far:</p>

<pre><code>// Create a random date between 2 months
$datestart = strtotime('01-11-2012');
$dateend = strtotime('01-12-2012');
$daystep = 86400;
$datebetween = abs(($dateend - $datestart) / $daystep);
$randomday = rand(0, $datebetween);

for($i=0; $i&lt; rand(10, 30) ;++$i)
{
echo "&lt;div&gt;" . date("d/m/Y", $datestart + ($randomday * $daystep)) ."&lt;/div&gt;";
}
</code></pre>

<p><strong>Update:</strong> I've now managed to get the code working thanks to <strong>Mihai Iorga</strong> but there is still the issue of sorting the dates from oldest to newest. How do I achieve this:</p>

<pre><code>// Create a random date between 2 months
$datestart = strtotime('01-11-2012');
$dateend = strtotime('01-12-2012');
$daystep = 86400;
$datebetween = abs(($dateend - $datestart) / $daystep);
$randomday = rand(0, $datebetween);

for($i=0; $i&lt; rand(10, 30) ;++$i)
{
$randomday = rand(0, $datebetween);
echo "&lt;div&gt;" . date("d/m/Y", $datestart + ($randomday * $daystep)) ."&lt;/div&gt;";
}
</code></pre>
