Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to always show full date of posting (publishing date as required by Google's Data Highlighter)?

I've been playing around with the Data Highlighter function in Google's Webmaster Center, and found out that that auto-tagging of forum discussions as Articles fails because it can not identify the publishing date, which looks like this:

Is there an easy way to always show the full date of posting (like "31 July 2014") at least in the initial posting of a discussion?

I'm on Vanilla 2.1 using a modified default template.



  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Don't know if there is a more easy way, but you can add a custom function to your /bootstrap.php:

    if (!function_exists('FormatDateCustom')) {
        function FormatDateCustom($Timestamp = '', $Format = '') {
  • Options
    MasterOneMasterOne ✭✭
    edited July 2014

    @R_J, can you please explain that in more details?

    I've taken a look, the function FormatDateCustom doesn't exist, but is checked on in library/core/class.format.php. I don't really know what to return with a FormatDateCustom function added to bootstrap.php, but it seems the formating magic takes place in library/core/class.format.php in

    public static function Date($Timestamp = '', $Format = '')

    @param string $Format The format string to use. Defaults to the application's default format.

    The part applying the different formating checks if $Format is set, so I think it's not set when called, because it then formats the date differently based on how long ago it's been posted in that function if $Format is empty.

    Where could the application's default format be set, so that it's used by that function?

    @manisso, no idea what your comment means.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Weil's schnell gehen muss kurz auf Deutsch:

    Die bootstrap wird vor allem anderen ausgeführt. Wenn du dort eine Funktion anlegst, ist sie für das gesamte Framework verfügbar.
    Die Stelle die du gefunden hast, an der diese Funktion abgefragt wird, überprüft, ob es diese Funktion gibt. Wenn ja, wird sie aufgerufen, damit sie die Ausgabensteuerung übernimmt. Wenn nein, macht die Standard Funktion weiter.

    Du musst also eine Funktion schreiben, die das Datum so ausgibt, wie du es brauchst. Es wird ein Timstamp übergeben. Ich glaube, mit der php Funktion date() kannst du ein Format ausgeben. Statt "Whatever..." muss also so was wie return(date($Timestamp, 'd.m.Y' )); dort stehen, aber da musst du leider selber weiter nachgoogeln (Ich kann immer gerade genug PHP um mich von einem zum nächsten Schritt zu hangeln ;) )

    Der Befehlt strftime ist auch ein spannender Ansatz, denke ich. Der soll Zeiten in lokalem Format ausgeben. Das lokale Format sollte übrigens auch in der Übersetzungsdatei stehen. Vielleicht nimmst du also statt 'd.m.y' den config Wert Gdn::Config('Garden.WieAuchImmerDasLokaleZeitFormatHeißt')

    Du musst ggf. auch noch eine Fehlerprüfung implementieren.

    Leider bin ich jetzt erst mal eine Weile vom Rechner, aber da findet sich bestimmt jemand, der dir weiterhilft - viel Glück!

  • Options
    x00x00 MVP
    edited July 2014

    data format are set in locale no need for custom functions.

    grep is your friend.

  • Options

    @x00 said:
    data format are set in locale no need for custom functions.

    Still, something is missing here, because $Format seems to be empty when public static function Date($Timestamp = '', $Format = '') is called in library/core/class.format.php, otherwise that code-block formating the posting date depending on the time that has passed since posting would not come into action.

    I'm sure @R_J‌'s approach would work, but there should be an easier solution already in place, hence the check if $Format is empty or not and the hint that it defaults to the application's default format (although it seems to be empty anyway).

    Is this something that should be configuarable in config.php?

  • Options

    it is not set in config.php is is set in locale

    you can put this in conf/locale.php

    if (!defined('APPLICATION')) exit();
    $Definition['Date.DefaultTimeFormat'] = '%l:%M%p';
    $Definition['Date.DefaultDayFormat'] = '%B %e';
    $Definition['Date.DefaultYearFormat'] = '%B %Y';
    $Definition['Date.DefaultFormat'] = '%B %e, %Y'; 
    $Definition['Date.DefaultDateTimeFormat'] = '%c'; 

    and format based on this

    grep is your friend.

  • Options
    peregrineperegrine MVP
    edited July 2014

    what x00 said is the way to do it.

    if you want the time to show on a post for the day as well as dd-mm-yyyy
    9:38AM 31-07-2014

    and dd-mm-yyyy for posts that are not current day.

    $Definition['Date.DefaultTimeFormat'] = '%l:%M%p %e-%m-%Y';
    $Definition['Date.DefaultDayFormat'] = '%e-%m-%Y';
    $Definition['Date.DefaultYearFormat'] = ' %e-%m-%Y';
    $Definition['Date.DefaultFormat'] =  '%l:%M%p %e-%m-%Y';


    $Definition['Date.DefaultTimeFormat'] = ' %e-%b-%Y (%l:%M%p)';
    $Definition['Date.DefaultDayFormat'] = '%e %b %Y';
    $Definition['Date.DefaultYearFormat'] = ' %e %b %Y';
    $Definition['Date.DefaultFormat'] =  '%l:%M%p %e %b %Y';

    if you want the time to show on a post for the current day as well as dd-mm-yyyy

    31-Jul-2014 (9:38AM)

    and dd-mm-yyyy for posts that are not current day.

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

  • Options
    hgtonighthgtonight ∞ · New MVP

    @R_J said:


    Does this mean "no longer searching"? I have only basic German understanding, but I love this word, whatever it means.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    It is from "etwas nachgucken" which means "to look something up". You certainly know "to google for something" as a synonym for look something up on the net and that is nachgoogeln :)

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    It is from "etwas nachgucken" which means "to look something up". You certainly know "to google for something" as a synonym for look something up on the net and that is nachgoogeln :)

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    What I love in the German language is the freedom you have when creating words. It's absolutely okay to combine nearly arbitrary words - although it's not always good style. One "famous" example that nearly every German knows is "Donaudampfschifffahrtskapitän" and what you can make of it. Rough translation would be Danube-steamboat-shipping-captain. I've even found an Englisch Wikipedia entry based on that.

    As I said before, that often is simply lazy and bad style bad it makes it quite easy to talk in expressive pictures.

    Nevertheless I really love the sound of British English. I've seen Macbeth at least 4 times in original language and I would visit that play at the next chance again without hesitation. Just the sound of that line alone... "Fair is foul, and foul is fair, hover through the fog and filthy air"

  • Options

    Well, those definitions in conf/locale.php do exactly what they are supposed to, but that solution has a negative side effect, it influences the whole system, even the display in the "In this Discussion" and "Who's Online" side-column boxes.

    The desired setting to work with Google's Data Highlighter would be something like this:

    $Definition['Date.DefaultTimeFormat'] = '%e %B %Y (%R)';
    $Definition['Date.DefaultDayFormat'] = '%e %B %Y';
    $Definition['Date.DefaultYearFormat'] = '%e %B %Y';
    $Definition['Date.DefaultFormat'] = '%e %B %Y';

    but that messes up the display in the "In this Discussion" and "Who's Online" side-column boxes, with entries getting wrapped into two lines depending on length of member name.

    For the Google Data Highlighter to work it would be enough if only the publishing date in the initial posting of a discussion would be shown in the desired format (%e %B %Y).

    No idea how this could be solved. Any more ideas?

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    That is the line in the code where the output of the discussions date is made:

    What you can do is to create a custom theme with following file: /themes/yourtheme/views/vanilla/discussion.php
    Copy the contents of the original view to that file and change the file of your new theme the way you like.

  • Options

    @R_J, would look like a plan, but with Gdn_Format::Date($Discussion->DateInserted the data only gets inserted and formated elsewhere. No clue on how to change the displayed format in that place.

    Such a little change (with the goal of having the publishing date properly formated in the initial posting of a discussion) seem to be way more complicated than anticipated. :(

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited August 2014

    You want to change the look/functionality of your board on one single place for one single purpose. Whenever you have the need to do something like that, you could expect that you have to dig some deeper into the code than just simply add one line of CSS somewhere.
    But all in all what you have to do is not very hard to achieve. You simply shouldn't change core files and so you have to override a view which means creating your own theme.

    By the way: if the google data highlighter works with html5 time tag, I would prefer doing something like that:

    echo Wrap(
        Anchor(Gdn_Format::Date($Discussion->DateInserted, 'html'), $Discussion->Url, 'Permalink', array('rel' => 'nofollow')),
        array('datetime' => date("Y-m-d H:i:s", $Discussion->DateInserted))

    That would enclose the normal link with a <time datetime="Y-m-d H:i:s"> tag and hopefully Google could use that information.

    For certain you can try it out first by simply modifying the original view, but you should end up with a custom theme and a reconstruction of the original view.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    But I haven't answered your question...

    Yes, it is formatted elsewhere but if you are overriding the view, you can simply drop that function call and replace it with a date("Y-m-d H:i:s", $Discussion->DateInserted)

  • Options

    I'm surprised that Data Highlighter doesn't work with the html5 <time> element in some of the 2.1 themes there is e.g.

    <time datetime="2014-08-01T09:30:22+00:00" title="August 1, 2014 10:30AM">10:30AM</time>

    See the datetime attribute, I don't really know enough about the highlighter TBH

    grep is your friend.

  • Options

    Since my theme is based on the default one it already has that HTML5 <time> line as shown by you, @x00, but it indeed does not work for the Google Data Highlighter as shown in the screenshot of my initial posting.

  • Options

    I wonder if it is actaully working as expected.


    Date and time information

    To specify dates and times unambiguously, use the time element with the datetime attribute. Here, the startDate property indicates the start date of an event. The value in the datetime attribute is specified using the ISO date format. Using this format lets you provide search engines with detailed date, time and—optionally—time zone in ISO format ("2009-10-15T19:00-08:00"), while still displaying the date on your page in a user-friendly way ("15 October 2009, 7PM").

    the only thing missing is the itemprop

    In other words the display date, is different from he the date time. I would ask on one of the mailing lists.

    grep is your friend.

  • Options

    Just checked again with the Google Data Highlighter by marking the shown date (in the visual form of "July 31") and choosing "Automatic Date/Time Detection" but it just does not work. It seems it only uses visual elements.

Sign In or Register to comment.