Results 1 to 2 of 2

Thread: Help with Events date output please (PHP)

  1. #1
    User
    Join Date
    06-19-09.
    Posts
    106

    Default Help with Events date output please (PHP)

    Hi, with my events-teaser template I'd like to achieve the following output for an event date:

    Fri 05 Jun 2015 - Sat 06 Jun 2015

    I've got the following code so far, but:

    • the day name is output in full rather than a 3-letter abbreviation – how can this be done?

    • are there any improvements / simplifications that can be made to the code?

    Many thanks for any help. I'm just not that knowledgeable with PHP.

    PHP Code:
    <?php if ($this->header): ?>
        <?php if ($this->firstDay): ?><span class="start-date"><?php echo $this->firstDay?>
        <?php endif; ?> 
        <?php echo $this->firstDate?><?php if ($this->endDate): ?></span>
        - <span class="end-date"><?php echo $GLOBALS['TL_LANG']['DAYS_SHORT'][Date('w'$this->end)] . " " Date('d M Y'$this->end); ?></span>
        <?php endif; ?>
    <?php 
    endif; ?>

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Your HTML output with this code is not valid.

    Use this code in your template to show the templates variables in front end.
    PHP Code:
    <?php $this->showTemplateVars(); ?>
    You see that $this->span is preconfigured. So you have to build up your on string here. You can do it with.
    PHP Code:
    <?php echo Date::parse('D d M Y'$this->startDate) . ' - ' Date::parse('D d M Y'$this->endDate); ?>
    http://de1.php.net/manual/de/function.date.php

    Second parameter of parse ($this->startDate) has to be a unix timestamp (a long integer number).

    Watch out that it fits to all event types. Maybe you have to put in a lot of IF clauses to achieve that.

    The long day name in your example output is done by $this->firstDay which is also preconfigured.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

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
  •