3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 753 Views |
-
Conditional with just part of a date

3 July 2010 at 8:24am
In my db I have a series of projects, each with a StartDate and EndDate.
So, for example...
Name: Project 1; StartDate: 1/1/2009; EndDate: 12/31/2009
Name: Project 2; StartDate: 7/1/2007; EndDate: 6/30/2012When displaying these projects, I only want to display the year AND if the start and end dates are in the same year, I would only like to show the year once (i.e., 2009 rather than 2009-2009)
So, for the above example, I'd like the output to be...
Project 1 (2009)
Project 2 (2007-2012)
How can I compare just the years from the date fields to determine whether to output (StartDate.Year) or (StartDate.Year-EndDate.Year) in my template?
Thanks so much!
Cheers,
Laurie -
Re: Conditional with just part of a date

7 July 2010 at 4:01pm
Rather than trying to do this in your template, add a new function to your Project object that creates the string for you.
eg:
function Years() {
$start = $this->dbObject('StartDate')->Year();
$end = $this->dbObject('EndDate')->Year();
return ($start == $end) ? $start : "{$start} - {$end}";
}Now in your template you can just do:
$Project.Name ($Project.Years)
-
Re: Conditional with just part of a date

8 July 2010 at 2:03am
Thanks Hamish!
I had tried something similar, but didn't have the syntax quite right. Your code worked perfectly. Thanks again.
| 753 Views | ||
|
Page:
1
|
Go to Top |


