Jump to content

[SOLVED] mysql lowest of 2 dates


whitedragon101

Recommended Posts

This is the string I am passing into the MySQL console so need a semicolon to terminate the string.  The following is an exact copy of a line I used in the console with DATEDIFF, which does return the difference between the two dates.

 

mysql > SELECT DATEDIFF('2012-10-09','2011-10-01');

works

 

However the query I need now is to get the lowest of the two dates and am again testing it in the console and:

 

mysql > SELECT MIN('2012-10-09','2011-10-01');

returns the error listed above.

Link to comment
Share on other sites

What I have is a table structured thus:

 

Job ID | Job Name | StartDate1 | EndDate1 | StartDate2 | EndDate2 | StartDate3 | EndDate3

 

I have been trying to get the earliest of the start dates (and after that I will need the latest of the end dates).

I want to display a table the just has the first two fields then the earliest and latest dates for each row like this:

 

Job ID | Job Name | Earliest Date | Latest Date

 

This is why I am having trouble finding a solution because it is for the ealiest and latest dates for each ROW not COLUMN.

 

I have been trying to do it like this.

($row_job_set is a row of a simple SELECT * query from the table described above ).

 

  <table border="1">
        <tr>
          <td>Job Id</td>
          <td>Job Name</td>
          <td>Earliest Date</td>
          <td>Latest Date</td>
        </tr>
        <?php do { 

                $startDate1 = $row_job_set['startDate1'];
                $startDate2 = $row_job_set['startDate2'];
                $startDate3 = $row_job_set['startDate3'];
                $lowestDateQuery = "SELECT MIN('$startDate1','$startDate2','$startDate3')";
        $lowestDate = mysql_query($lowestDateQuery);
	$dRow = mysql_fetch_row($lowestDate);
	$dResult = mysql_result($dRow,0);
	$totalRows_lowestDate= mysql_num_rows($lowestDate);
	?>
          <tr>
            <td><?php echo $row_job_set['job_id']; ?></td>
            <td><?php echo $row_job_set['job_name']; ?></td>
            <td><?php echo $totalRows_lowestDate  ?> </td>
            <td>Not yet implimented</td>
          </tr>
          <?php } while ($row_job_set = mysql_fetch_assoc($job_set)); ?>
      </table>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.