Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

show date & time for comments (except the same day) but still only show date in thread-overview

edited June 2012 in Vanilla 2.0 - 2.2

ok, i know it's a bit confusing and i'm starting to think i'm confusing myself more and more but i tried about thousands of possibilities now and i guess i'm losing track... :-P

so what i want is:

  • _in_ discussions:
    • for comments at the same day only show time (as usual)
    • for older comments show date **and** time ('%d %B - %R')
  • at discussion overview:
    • for discussions where last comment was at the same day only show time (as usual)
    • for discussions where last comment was earlier still only show date

i alredy tried many variatons of-date($Object->DateInserted, ('Y m d') == date($Now, ('Y m d')) and similar stuff in various files but nothing ever worked... is there a much easier solution which i just can't see or what am i doing wrong?

thanks for help in advance!

Best Answers


  • 422422 Developer MVP
    edited June 2012 Accepted Answer

    Search for timeago


    422 Real Estate Australia , now open Check it out

  • that gives me 4 results:

    • 1. Display full timestamp -- _just how to change time format_
    • 2. & 3. "How did wikihow forum realize to show "minutes ago" and not date/time?" -- _still simple question of time-format_
    • 4. Change style based on time/date? -- _looks quite interesting but still quite complicated (with image-file and stuff), shouldn't this be possible in a less complicated way?_

    in the class.format-file it's quite easy to define, so it also should be in other files or what's my mistake in thoughts?

  • 422422 Developer MVP

    I dont understnd your question.

    You want to change Posted:9.24 am to Posted:4 minutes ago ?

    422 Real Estate Australia , now open Check it out

  • no, not at all.

    i want to change "posted april 24" to "posted april 24 - 13:22h" but only in discussions and only if the comment is not from the same day... so i changed defaultdateformat to '%d %B - %R'... but then there's the problem that in the thread-overview the format is changed too of course (and that doesn't look good). so i have to add something that changes that again, but only for the thread-overview.

    the other version is that i only change the time format in the theme/view/discussion folder, but then i have to add something ("if-else" like mentioned in first posting) which because of an unknown reason doesn't work... so why does this not work:

    $Now = time();
    $posttime = Gdn_Format::Date($Object->DateInserted);

    if (date($posttime, 'Y m d') == date ($Now, 'Y m d'))

  • peregrineperegrine MVP
    Accepted Answer

    you could also take a look at the Unreadicon plugin

    and modify it to your needs.

    It will show you how to test for time difference and then you can reformat the time in a plugin or in the helper_functions.php file.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • ok, thanks a lot for the idea, i took a short look at the code of the plugin now and it seems to contain some new ideas, will have a closer look at it soon... :-) (now i have to get some sleep cause it's 3am here)
    and i forgot to mention that, but i'm working in the helper-functions.php file most of the time...

  • 422422 Developer MVP

    Shouldnt be to difficult all that info is stored. Best of luck

    422 Real Estate Australia , now open Check it out

  • if it was that easy for me i wouldn't still be here... i'm cunfused... i think i got pretty close but i have one more question:

    $indate = date($Sender->EventArguments['Comment']->DateInserted);
    echoes: "2012-06-10 00:06:26"

    $indate = date('Y m d', $Sender->EventArguments['Comment']->DateInserted);
    echoes "1970 01 01"


  • 422422 Developer MVP
    edited June 2012

    Epoch. You more than likely need to define another var, then parse it like $MyCustomDateTime

    422 Real Estate Australia , now open Check it out

  • edited June 2012

    finally i found a solution, i just used a little trick (i just cut the date-string)... so if anyone is interested, here's the code for the helper-functions.php file in the "discussion" folder:

    <.span class="DateCreated">

    >             $indate = $Sender->EventArguments['Comment']->DateInserted;
    >             $subindate = substr($indate, 0, 10);
    >             $subyear = substr($indate, 0, 4);
    >             $toyear = date('Y');
    >             $todate = date('Y-m-d');
    >              if ($todate == $subindate) {
    >              echo Anchor(Gdn_Format::Date($Object->DateInserted), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));
    >             } else {
    >                if ($subyear == $toyear) {
    >             echo Anchor(Gdn_Format::Date($Object->DateInserted, ('%d %B / %R')), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));   
    >                } else {
    >                   echo Anchor(Gdn_Format::Date($Object->DateInserted, ('%B %Y')), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));   
    >                }
    >             }
    >             ?>
Sign In or Register to comment.