Results 1 to 7 of 7

Thread: Date Formats

  1. #1
    User
    Join Date
    12-11-09.
    Location
    New York, NY USA
    Posts
    87

    Default Date Formats

    Hi All,

    I would prefer to have a date that is formated like 'February 2, 2010' which I think should be the formated with the following string 'F d, Y' This however generates a general system error like so.

    Code:
    Fatal error: Uncaught exception Exception with message Invalid date format "F d Y" thrown in C:\xampp\htdocs\abmac-tl\system\libraries\Date.php on line 187
    
    #0 C:\xampp\htdocs\abmac-tl\system\libraries\Widget.php(540): Date->getRegexp('F d Y')
    #1 C:\xampp\htdocs\abmac-tl\system\modules\backend\TextField.php(105): Widget->validator('January 15 2010')
    #2 C:\xampp\htdocs\abmac-tl\system\libraries\Widget.php(420): TextField->validator('January 15 2010')
    #3 C:\xampp\htdocs\abmac-tl\system\modules\backend\DataContainer.php(251): Widget->validate()
    #4 C:\xampp\htdocs\abmac-tl\system\drivers\DC_Table.php(1473): DataContainer->row()
    #5 C:\xampp\htdocs\abmac-tl\system\modules\backend\Backend.php(208): DC_Table->edit()
    #6 C:\xampp\htdocs\abmac-tl\typolight\main.php(99): Backend->getBackendModule('news')
    #7 C:\xampp\htdocs\abmac-tl\typolight\main.php(294): Main->run()
    #8 {main}
    My config is
    $GLOBALS['TL_CONFIG']['dateFormat'] = 'F d, Y';
    $GLOBALS['TL_CONFIG']['datimFormat'] = 'F d, Y';

    Whats the correct formating string?

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Date Formats

    Yes! We ran into the same issue over here a couple of weeks ago on a site we were doing.

    I did find this post on the old forums: http://www.typolight.org/forum/message/1559.html. Unfortunately there was no explanation or solution given, just a bunch of people basically acknowledging that the problem exists.

    The best I can gather is that the global date format you define in settings has to be numeric only -- not sure what the technical reasons are and would welcome any insight.

    Unfortunately I don't have access to the code (it was on a friend's Dev server), but I THINK we solved it by going into the news template and specifying the date like the following:

    Code:
    <?php echo date("F j, Y", $this->time); ?>
    In our case we used "j" because that one doesn't add the leading 0 to single-digit days.
    Brian

  3. #3
    User
    Join Date
    12-11-09.
    Location
    New York, NY USA
    Posts
    87

    Default Re: Date Formats [WORKAROUND]

    Hey that worked beautifully!

    So restated you can override the system date format with a custom format.

    Copy and edit the appropriate News template and swapped out
    the date code
    Code:
    <?php  echo $this->date;  ?>
    with

    Code:
    <?php echo date("F j, Y", $this->time); ?>

  4. #4
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Date Formats

    Correct -- that will work, specifically for news items. (Common tripping point we ran into -- $this->date is what news uses by default to show date & time. We tried it with that first, but it broke -- I guess because of how it's formatted. So we tried $this->time instead, and that did the trick).

    Events have different variables, and I don't know about anything else.

    But when in doubt, you can drop this into any template:

    Code:
    <?php echo '<pre>'; $this->showTemplateVars(); echo '</pre>'; ?>
    And when you refresh it will show you all the available template variables, so a few minutes of trial and error will get you the one you need.
    Brian

  5. #5
    User
    Join Date
    12-11-09.
    Location
    New York, NY USA
    Posts
    87

    Default Re: Date Formats

    Thats good to know! Thanks again.

  6. #6
    Experienced user
    Join Date
    06-10-09.
    Location
    Atlanta, Georgia
    Posts
    611

    Default Re: Date Formats

    TYPOlight prefers numeric date formats for the backend, which are set in System > Settings. From Layout > Site structure, you can define frontend date, time, and date + time formatting by editing your website root. This is one of many reasons why it's good to use a website root and place all pages beneath it.

  7. #7
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Date Formats

    Thanks, Ben. That's good to know. I've seen this recommended twice now, and will definitely try in the future.
    Brian

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •