Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Date Range Method

Go to End

2 Posts   2736 Views


Community Member, 176 Posts

28 August 2009 at 12:07am

I've found the $Date.Range(date2) method at Trying to use it I came across the same errors as post in the archive at As it seems I'm not the only one experiencing the issue I thought I would post the error again, and my solution.

When trying to call $Date.RangeString($EndDate) from a template I saw the error:

Parse error: syntax error, unexpected T_STRING, expecting ')' in on line 99

Which I understand is a result of how the templates work.


next which resulted in the error:

Fatal error: Call to a member function RangeString() on a non-object in \blog\code\BlogEntry.php on line 188

The final solution that worked for me was (BlogEntry.php):

// To create a complete example I've included the EndDate db entry:
static $db = array(
	"Date" => "SSDatetime",
	"EndDate" => "SSDatetime",

 * Outputs date span or single date if no end date defined
 function DateRange() {
	 $start = new Date();

	 if (!is_null($this->EndDate)) { // Check if there is an end date
		 $end = new Date();
		 return $start->RangeString($end);
	 } else {
		 return $start->Long();

For beginners I'm using $DateRange in the templates (e.g. to output the daterange.


Community Member, 12 Posts

12 December 2009 at 4:41am

Great solution, thanks!