$this->date outputs different formats
It seems that when using $this->date to output the date of an calendar event, the output is different regarding which template is used.
For example:
In my event_upcoming.tpl $this->date outputs: 2010-01-10
In my event_default.tpl $this->date outputs: 2010-01-10 (10:00 - 11:00)
Shouldn't $this->date output the same date format?
Anyway, this gives me some problem, because I want to format the time and date to this format (Swedish):
Söndag 10 Januari – Kl 10:00 - 11:00
I have managed to accomplish this in my event_upcoming.tpl by using this code:
Code:
<div class="date"><span class="date">
<?php echo $this->parseDate("l j F", strtotime($this->date)); ?></span>
<?php if ($this->time): ?> – Kl <span class="time"><?php echo $this->time; ?></span><?php endif; ?>
</div>
But I can't really get it to work in my event_default.tpl. Because the date format of $this->date is different in this template, I cannot use the same code.
I found this tutorial on how to separate time and date fields, but it doesn't work. It gives the following error:
Code:
Warning: date_format() expects parameter 1 to be DateTime, boolean given in /public_html/templates/event_default.tpl on line 5
Anyone knows how to get this to work?
And also why the default date format is different in different templates?
Re: $this->date outputs different formats
Hey Ola,
I think most of the modules spit out a "$this -> tstamp" or "$this -> timestamp" as well (I know the news ones do, so the event ones probably do as well). I would try those next -- if either work, you can run it through the date() function to get it into any format you need.
Brian
Re: $this->date outputs different formats
Thanks for the suggestions.
I tried them, but it seems like that $this->timestamp just outputs todays date, and $this->tstamp just outputs the date that the event was created.
So no luck yet.
Is there a way to see all properties of a single event that can be used with $this->...?
Re: $this->date outputs different formats
Hi Ola,
jus a second to find the code you can use in templates...
10 seconds later :-)
You can replace
Code:
<?php echo $this->date; ?>
with
Code:
<?php echo $this->parseDate("d.m.Y", $this->time); ?>
and set your date / time putput by adding it in the command like .
Using this
Code:
<?php echo $this->date; ?>
will grab your date & time definitions you made in settings.
Re: $this->date outputs different formats
Quote:
Originally Posted by planepix
You can replace
Code:
<?php echo $this->date; ?>
with
Code:
<?php echo $this->parseDate("d.m.Y", $this->time); ?>
and set your date / time putput by adding it in the command like
.
Doesn't work. $this->time outputs nothing at all.
Quote:
Originally Posted by planepix
Using this
Code:
<?php echo $this->date; ?>
will grab your date & time definitions you made in settings.
Nope, doesn't work. I changed the settings in backend and removed the timestamp, but no change on the output.
Did a test to show you how the output render an event in my two templates:
The date/time setting in backend was just Y-m-d. (Not the default Y-m-d H:i)
event_upcoming.tpl (module that renders the upcoming five events):
$this->date; outputs 2010-01-11
$this->time; outputs 18:00 - 20:00
event_default.tpl (module that renders a single event):
$this->date; outputs 2010-01-11 (18:00 - 20:00)
$this->time; outputs [nothing]
Is this difference a feature or a bug? :)
So, my problem is, I don't now how to render the date, without the timestamp in my event_default.tpl template. Suggestions are welcome! :)
Re: $this->date outputs different formats
Quote:
Originally Posted by Ola
So, my problem is, I don't now how to render the date, without the timestamp in my event_default.tpl template. Suggestions are welcome! :)
Try this:
add at the bottom of your event_default.tpl
[code=php:1pekg3ns]<span class="syntaxhtml"><pre><?php*$this->showTemplateVars();*?></pre></span>[/code:1pekg3ns]
reload page, see which variable have timestamp and next:
[code=php:1pekg3ns]<span class="syntaxhtml"><?php*echo*date("d/m/Y",*$this->startDate);*?></span>[/code:1pekg3ns]
of course in this case I assume that "startDate" is timestamp
Re: $this->date outputs different formats
Quote:
Originally Posted by qrczak
Try this:
add at the bottom of your event_default.tpl
[code=php:1g6vdtq7]<span class="syntaxhtml"><pre><?php*$this->showTemplateVars();*?></pre></span>[/code:1g6vdtq7]
Woohoo, you are my hero! I finally found out. Thanks qrczak! :D
Re: $this->date outputs different formats
Nice to know you find a solution Ola.