Kyle Monti
Kyle Monti

Reputation: 704

Php date format is outputting the wrong date

I have dates and times setup in the database separately. start is in YYYY-MM-DD format and time is in HH:MM:SS format. I'm trying to modify the start date to show the date in a readable format.

I've tried to output using php and I get "Wednesday, Dec 31 1969" which is nothing like I want. (right format, but the date isn't anything I have in the database).

And i've used DATE_FORMAT('start','%W, %M %d %Y') AS startbut my select function has it order by start and it doesn't give me the right order and values specified. but format is right.

my php code is

$sql = "SELECT `title`, `time`, `start`, `showFeed` FROM calender WHERE length('column') > '0' and showFeed=1 ORDER BY `start` ASC LIMIT 0,4";

/*  DATE_FORMAT(`start`,'%W, %M %d %Y') AS start   */

    $result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);

echo "<div class=\"eventfeed\">";
echo "<ul>";

foreach ($result as $row){
$dt = $row['start'];
$ts = $row['time'];

$date = strtotime( $dateout );
$dateout = date( 'l, M j Y', $phpdate );



    echo "<dl>";
    echo "<dt>". $row['title']. "</dt>";
    echo "<dd>".  $dateout;
    echo "</dl>";

}

echo "</ul>";
echo "</div>";

$dbh = null;

I don't know what possibly I'm doing wrong. I've done this before and for some reason formatting dates isn't working this time around.

Upvotes: 0

Views: 623

Answers (1)

Dave
Dave

Reputation: 29121

Try this:

<?php
$dt = $row['start'] . ' ' . $row['time'];
echo date('l, M j Y', strtotime($dt));

I'm not sure if it was just a typo, or if it's your code, but - you're referencing $dateout before it's set, and $phpdate, which is never set.

Upvotes: 1

Related Questions