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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

date.ago wrong calculation?

Go to End

2 Posts   1156 Views


Community Member, 83 Posts

12 November 2010 at 1:14am


in the Date-Class there is a method Ago().
But i guess its calculating not correct.

Today we have: 2010-11-11
In DB the date is: 2010-11-10

So, $datum.Ago should write "1 day ago" but I get "2 days ago".

Or am I understanding it wrong?


Community Member, 83 Posts

21 November 2010 at 3:21am

ok, i was using the wrong class.

i did:

$date = new Date();
return $date->Ago();

But the method setValue() of the Date-Class is creating a Date in format "Y-m-d".
So hour, minute and second of $this->Created are considered as 00:00:00.

Instead I had to use the class SS_Datetime

$date = new SS_Datetime();
return $date->Ago();

maybe this is useful for anyone.

One more notice: In german it should be formulated "vor 9 Tagen".
Mayby this is diffucult to do with translation, because "Tage" is the correct plural for "Tag".
But in this case it has to be "vor 9 Tagen".