Jump to content

Get publishedDateTime


fabjeck
 Share

Recommended Posts

Hello Community

On my website I have a newsfeed, where I want to display the datetime of when the article was published. I know there is a module called "ProcessWirePublishDate". But is it possible that it only returns the date without the time? How could I fix it.

Thanks for helping :)

Link to comment
Share on other sites

Welcome to the forums @fabjeck. If you are using native ProcessWire published page property:

echo date('d F Y', $page->published);// e.g. 07 January 2017

I can't remember when 'published' property was added to ProcessWire, but hopefully it should work in the version you are running.

  • Like 1
Link to comment
Share on other sites

15 minutes ago, fabjeck said:

I can't sort the pages by date.

$articles = $pages->find('template=article, sort=-published, limit=10');// latest first
//$articles = $pages->find('template=article, sort=published, limit=10');// oldest first

foreach ($articles as $a) {
	echo $a->title . ': ' . date('d F Y', $a->published) . '<br>';
}

Is that what you are looking for?

  • Like 1
Link to comment
Share on other sites

1 hour ago, kongondo said:

$articles = $pages->find('template=article, sort=-published, limit=10');// latest first
//$articles = $pages->find('template=article, sort=published, limit=10');// oldest first

foreach ($articles as $a) {
	echo $a->title . ': ' . date('d F Y', $a->published) . '<br>';
}

Is that what you are looking for?

I had it like that, but missed a coma after the "sort" argument...but thanks for your help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...