Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Date Range Method

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1377 Views
  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Date Range Method Link to this post

    Hi all. I'm follow the Date Documentation here: http://doc.silverstripe.com/doku.php?id=date

    I have two dates, StartDate, and EndDate, and I see the cool method Range in the documentation.

    $Expires.Range(date2) - You give a second date and it returns a condensed english “phrase” for that date range. E.g. “12 - 18 June” or “12 June - 23 August”.


    In my template, I am trying to use this method as follows:

    $StartDate.Range(EndDate)


    This returns nothing. Despite both EndDate and Startdate displaying by themselves just fine. Any ideas?
    Aaron

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Date Range Method Link to this post

    Missing a $ in front of end date by any chance?

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Date Range Method Link to this post

    Sorry Will, I should have added that that was the first thing I tried. If I change the code to:

    $StartDate.Range($EndDate)


    I get a parse error:

    Parse error: syntax error, unexpected T_STRING, expecting ')' in C:\WINDOWS\Temp\silverstripe-cacheW--Viva_Expeditions-html\.cacheW..Viva_Expeditions.html.themes.vivaexp.templates.Tour.ss on line 344

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Date Range Method Link to this post

    Strange... maybe you cant pass variables into Range in the template. Might have to try somethin in a PHP method then I guess. As if your field EndDate and $EndDate dont work I dont know what else you could use!

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Date Range Method Link to this post

    Thanks for trying Will. The Documentation above specifically states:

    The following $ variables can be used in the template. Replace “Expires” with the name of your database field.
    ....
    $Expires.Range(date2)


    I have tried using range in a function on the page controller, but I get a 'non-object' error. May be a bug?

    1377 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.