Hi guys. i have an event page that displays events from database. in my database I have a column with datetime format. is there a way to only get the date or time separate from each other in a select to be displayed?
php:

<?php
require "connection.php";
$sessid = $_SESSION['sess_user_id'];
$check = $dbh->prepare("SELECT * FROM event WHERE euser_id = $sessid ORDER BY start_event ASC ");
$check->execute(array('euser_id'));

if($check->rowCount() > 0)
{
    $check->setFetchMode(PDO::FETCH_ASSOC);
    while($row = $check->fetch())
    {
        $dstart = $row['start_event'];

        echo 
        "<tr>
            <td>$dstart</td>
        </tr>";
    }
}
?>

so right now in the database column start_event its like : 2014-08-09 13:30:00:00000 and

what i want to be displayed in the event page is the date only: 2014-08-09.

i found this link on stackoverflow but it shows the function being used in the where clause and well thats not what i want.

i tried the DATE function like this:

while($row = $check->fetch())
{
    $dstart = $row['start_event'];
    $dstarting = DATE($dstart);

    echo 
    "<tr>
        <td>$dstarting</td>
    </tr>";
}

but i guess im not doing it right because it still shows 2014-08-09 13:30 in the event page. and also if its possible to change the format of the date when displayed; instead of yyyy-mm-dd it shows dd-mm-yyyy.

TIA!

The DATE() function is a MYSQL function PHP has date();
Why don't you use substr function?
or you can try this: $dstarting = date('d-m-Y', strtotime($dstart));
Refer this for more possible formats to print date: Click Here

i got it. did this:

$dstart = $row['start_event'];
$dstarts = strtotime($dstart);
$formatDate = date('M d, y', $dstarts);

echo 
    "<tr>
        <td>$formatDate</td>
     </tr>";

result = May 23, 11

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.