Search code examples
phpdatabasejoomla

how can i change date format for joomla to d/m/Y?


I tried to change the date format of Joomla 3 DB table after several attempts like this

echo date_format("end_date", "%d/%m/%Y");
echo $result->format('$result->end_date', 'd-m-Y');

// also tried to get kind of result March 10, 2001, 5:16 pm
echo date_format("end_date", "F j, Y, g:i a");
echo date_format("$result->end_date", "F j, Y, g:i a");
echo date_format('$result->end_date', 'F j, Y, g:i a');
echo date_format({$result->end_date}, 'F j, Y, g:i a');
echo date($result->end_date}, 'F j, Y, g:i a');
echo date('$result->end_date', 'F j, Y, g:i a');
echo "<time datetime='$result->end_date'>"  "</time>";

, checked all relative posts on stack overflow for the similar type of code, all lessons, and examples but couldn't change this end_date format to d/m/Y

<?php
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $select = array(
        $db->quoteName('title'),
        $db->quoteName('id'),
        $db->quoteName('start_date'),
        $db->quoteName('end_date')
    );
    $query->select(array($select));
    $query->from($db->quoteName('#__rbid_auctions'));
    $query->order($db->quoteName('id') . " DESC");
    $query->setLimit(3);
    $db->setQuery($query);
    $results = $db->loadObjectList();

    // display the results
    foreach ( $results as $result) {
        echo "<a href=\"index.php?option=com_rbids&task=viewbids&id={$result->id}\">{$result->title} . </a>";
        echo "<p>" . $result->start_date . "</p>";
        echo "<p>" . $result->end_date . "</p>";
    }
?>

Thanks in advance


Solution

  • try using the following:

    // instantiate a new Joomla Date Object 
    $date = new JDate($result->start_date);
    
    // echo the formatted date
    echo $date->format('F j, Y, g:i a');
    

    Hope it helps,

    Gez