Jump to content

[solved] Problem with DATE output format


drilonb
 Share

Recommended Posts

Hello Processwire i have trouble with date in blog post, i like to put date when i post a article

i am puting in template like this

<?php
    $languages = $session->language;
    $children = $pages->get("/news/")->children("sort=-created, limit=5");
    foreach($children as $news) {
        if($session->language) {
            $titulli = $news->{'headline_'.$session->language};
            $shkurtimi = $news->{'body_'.$session->language};
        }else{
            $shkurtimi = $news->body_en ;
            $titulli = $news->headline_en ;
        }
        $shkurti = substr( $shkurtimi , 0, 250);
        echo "
          <h2> >$titulli | {$news->created} </h2>
          <p><a class='linkulajme' href='{$news->url}'>$shkurti</a></p>
        ";
    }
    echo "<ul class='MarkupPagerNav'>";
    echo $children->renderPager();
    echo "<ul>";

and in web look only like this:

<h2> >$titulli | {$news->created} </h2>    (>Viti i ri | [b]1310476537[/b])

PS, also i create a field datat and select date time but show only this date in page  

>Viti i ri | 12 / 31 / 1969 - 7:00 pm

//edits:

14:07 adamkiss: Edited title & syntax formatting. Please use BBCode's [ code ] tag (without spaces) to format PHP (or other) code. Also, use as descriptive title/subject as possible.

15:00 adamkiss: added solved tag

Link to comment
Share on other sites

Since $page->created is a system created timestamp, I believe you can't have it returned formatted, as this field simply returns timestamp. Use date() function with your desired format, e.g.:

 <?php
   $dateFormatted = date('d.m.Y', $page->created);
   echo "<h2> $title | $dateFormatted</h2>";
Link to comment
Share on other sites

I'm thinking maybe we should have built-in date formatting for the 'created' and 'modified' fields. What do you guys think, maybe an alternate syntax for accessing the formatted version? Like $page->dateCreated is the formatted version of $page->created? It would just be formatted by whatever is set to $config->dateFormat.

Link to comment
Share on other sites

  • 2 weeks later...

I'm thinking maybe we should have built-in date formatting for the 'created' and 'modified' fields. What do you guys think, maybe an alternate syntax for accessing the formatted version? Like $page->dateCreated is the formatted version of $page->created? It would just be formatted by whatever is set to $config->dateFormat.

Hi, Ryan

I see two sides here ;)

The good is that it makes template code cleaner and I don't have to open my php cheatsheet.

The bad is that such things make api bloat as time goes and make me lazier  :)

And IMHO very often various date formatting is needed depending on the context.

Link to comment
Share on other sites

It's a good idea ryan, but I agree with slkwrm on this one - on a lot of sites I've worked on I'll format dates differently for different things.

News articles on a site's homepage tend to get a long version of the date (Wednesday 20th July 2011) whereas on the same page I might have a little list on a sidebar pulling just page titles for "last 10 files uploaded" or something whereby it would just be the title and a short version of the date, so the date format would be 20th Jul '11 or something like that.

I have seen it in forum software where there are config settings for both occasions though, so a config setting for long date format and short date format and to be honest that might not be a bad way to go as the majority of the time I'd only use two different options.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...