ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

PHP and dates



Got dates stored in a MySQL database in the format: 2009-05-02 00:00:00

Pulling these out into a table using a mysql_fetch_array and would like them to display as "2nd May" instead of 2009-05-02 00:00:00. Easiest way to go about doing it? I have tried finding results on Google, so please don't suggest that ;)

PHP:
 <?php  //create sql query for the calendar
    $query = 'SELECT meet_date, meet_name, cir_name, meet_table, meet_entries FROM meeting, circuit WHERE meeting.meet_cir = circuit.cir_id ORDER BY meet_date ASC;';
    $result = mysql_query($query);
    
    
    
?>

    <div class="leftcontent">
        <h2>2009 Calendar</h2>
        <p>
            <table>
                <tr>   <th>Date</th>   <th>Meeting</th>    <th>Circuit</th>    <th>Timetable</th>    <th>Entry List</th>    </tr>
<?php while($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>" .$row['meet_date']. "</td>";
    echo "<td>" .$row['meet_name']. "</td>";
    echo "<td>" .$row['cir_name']. "</td>";
    echo "<td>" .$row['meet_table']. "</td>";
    echo "<td>" .$row['meet_entries']. "</td>";
    echo "</tr>";
}
?>
            </table>
 

KDF

  Audi TT Stronic
Got dates stored in a MySQL database in the format: 2009-05-02 00:00:00

Pulling these out into a table using a mysql_fetch_array and would like them to display as "2nd May" instead of 2009-05-02 00:00:00. Easiest way to go about doing it? I have tried finding results on Google, so please don't suggest that ;)

PHP:
 <?php  //create sql query for the calendar
    $query = 'SELECT meet_date, meet_name, cir_name, meet_table, meet_entries FROM meeting, circuit WHERE meeting.meet_cir = circuit.cir_id ORDER BY meet_date ASC;';
    $result = mysql_query($query);
    
    
    
?>

    <div class="leftcontent">
        <h2>2009 Calendar</h2>
        <p>
            <table>
                <tr>   <th>Date</th>   <th>Meeting</th>    <th>Circuit</th>    <th>Timetable</th>    <th>Entry List</th>    </tr>
<?php while($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>" .$row['meet_date']. "</td>";
    echo "<td>" .$row['meet_name']. "</td>";
    echo "<td>" .$row['cir_name']. "</td>";
    echo "<td>" .$row['meet_table']. "</td>";
    echo "<td>" .$row['meet_entries']. "</td>";
    echo "</tr>";
}
?>
            </table>

just use

$phpdate = strtotime( $mysqldate );

encapsulate that in another function to get what you want.

$phpdate = date( "jS F", strtotime( $mysqldate ));


PHP:
 <?php  //create sql query for the calendar
    $query = 'SELECT meet_date, meet_name, cir_name, meet_table, meet_entries FROM meeting, circuit WHERE meeting.meet_cir = circuit.cir_id ORDER BY meet_date ASC;';
    $result = mysql_query($query);
    
    
    
?>

    <div class="leftcontent">
        <h2>2009 Calendar</h2>
        <p>
            <table>
                <tr>   <th>Date</th>   <th>Meeting</th>    <th>Circuit</th>    <th>Timetable</th>    <th>Entry List</th>    </tr>
<?php while($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>" .date( "jS F", strtotime($row['meet_date'])). "</td>";
    echo "<td>" .$row['meet_name']. "</td>";
    echo "<td>" .$row['cir_name']. "</td>";
    echo "<td>" .$row['meet_table']. "</td>";
    echo "<td>" .$row['meet_entries']. "</td>";
    echo "</tr>";
}
?>
            </table>


Simples
 


Top