BaronGrivet
BaronGrivet

Reputation: 4424

How to cast SilverStripe variable in Controller extension

I have the following code:

class Page_Controller extends ContentController
{
    public function TimeNow() {
        return date('Y-m-d H:i:s');
    }
}

But the following template code doesn't work:

$TimeNow.Format(Ymd\THis)

I'm guessing this is because TimeNow isn't cast as an SS_Datetime object (which inherits the Format method).

How do I cast TimeNow as SS_Datetime?

Upvotes: 2

Views: 126

Answers (1)

cryptopay
cryptopay

Reputation: 1082

Do this instead:

public function TimeNow() {
    return SS_DateTime::now();
}

Upvotes: 5

Related Questions