Skip to main content
date format
Source Link
RichardB
  • 3.1k
  • 11
  • 14

The following should work for what it sounds like you are trying to achieve. If you are on an article page, it displays the published date of that article or else shows nothing.

// FIRSTLY CHECK THAT THE PAGE THE MODULE APPEARS ON IS AN ARTICLE
$nameofcomponent = JRequest::getVar('option');
$viewofcomponent = JRequest::getVar('view');

if ($nameofcomponent=="com_content" && $viewofcomponent=="article" ) {
    
    // IT IS AN ARTICLE, SO GET THE ID OF THE ARTICLE
    $idofarticle = JRequest::getInt('id');
    
    // LOAD THE MODEL OF COM_CONTENT
    $model = JModelLegacy::getInstance('Article', 'ContentModel');
    // USE THE GETITEM FUNCTION OF THE MODEL TO RETURN THE DETAILS
    $article = $model->getItem($idofarticle);
    
    
      // FORMAT AND PRINT THE DATE TO THE SCREEN
    echo  $date = new JDate($article->created;>created);
      echo $date->format('j M Y');

}

If this is what you are trying to do, however, then it sounds like there may be a design issue - I can't imagine a usibility reason why you'd want to show this information in a module rather than the component area.

The following should work for what it sounds like you are trying to achieve. If you are on an article page, it displays the published date of that article or else shows nothing.

// FIRSTLY CHECK THAT THE PAGE THE MODULE APPEARS ON IS AN ARTICLE
$nameofcomponent = JRequest::getVar('option');
$viewofcomponent = JRequest::getVar('view');

if ($nameofcomponent=="com_content" && $viewofcomponent=="article" ) {
    
    // IT IS AN ARTICLE, SO GET THE ID OF THE ARTICLE
    $idofarticle = JRequest::getInt('id');
    
    // LOAD THE MODEL OF COM_CONTENT
    $model = JModelLegacy::getInstance('Article', 'ContentModel');
    // USE THE GETITEM FUNCTION OF THE MODEL TO RETURN THE DETAILS
    $article = $model->getItem($idofarticle);
    
    
    // PRINT THE DATE TO THE SCREEN
    echo $article->created;

}

If this is what you are trying to do, however, then it sounds like there may be a design issue - I can't imagine a usibility reason why you'd want to show this information in a module rather than the component area.

The following should work for what it sounds like you are trying to achieve. If you are on an article page, it displays the published date of that article or else shows nothing.

// FIRSTLY CHECK THAT THE PAGE THE MODULE APPEARS ON IS AN ARTICLE
$nameofcomponent = JRequest::getVar('option');
$viewofcomponent = JRequest::getVar('view');

if ($nameofcomponent=="com_content" && $viewofcomponent=="article" ) {
    
    // IT IS AN ARTICLE, SO GET THE ID OF THE ARTICLE
    $idofarticle = JRequest::getInt('id');
    
    // LOAD THE MODEL OF COM_CONTENT
    $model = JModelLegacy::getInstance('Article', 'ContentModel');
    // USE THE GETITEM FUNCTION OF THE MODEL TO RETURN THE DETAILS
    $article = $model->getItem($idofarticle);
    
    
      // FORMAT AND PRINT THE DATE TO THE SCREEN
      $date = new JDate($article->created);
      echo $date->format('j M Y');

}

If this is what you are trying to do, however, then it sounds like there may be a design issue - I can't imagine a usibility reason why you'd want to show this information in a module rather than the component area.

Source Link
RichardB
  • 3.1k
  • 11
  • 14

The following should work for what it sounds like you are trying to achieve. If you are on an article page, it displays the published date of that article or else shows nothing.

// FIRSTLY CHECK THAT THE PAGE THE MODULE APPEARS ON IS AN ARTICLE
$nameofcomponent = JRequest::getVar('option');
$viewofcomponent = JRequest::getVar('view');

if ($nameofcomponent=="com_content" && $viewofcomponent=="article" ) {
    
    // IT IS AN ARTICLE, SO GET THE ID OF THE ARTICLE
    $idofarticle = JRequest::getInt('id');
    
    // LOAD THE MODEL OF COM_CONTENT
    $model = JModelLegacy::getInstance('Article', 'ContentModel');
    // USE THE GETITEM FUNCTION OF THE MODEL TO RETURN THE DETAILS
    $article = $model->getItem($idofarticle);
    
    
    // PRINT THE DATE TO THE SCREEN
    echo $article->created;

}

If this is what you are trying to do, however, then it sounds like there may be a design issue - I can't imagine a usibility reason why you'd want to show this information in a module rather than the component area.