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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1229 Views

Avatar
lx

Community Member, 83 Posts

12 November 2010 at 1:14am

Hi,

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?
thanks

Avatar
lx

Community Member, 83 Posts

21 November 2010 at 3:21am

ok, i was using the wrong class.

i did:

$date = new Date();
$date->setValue($this->Created);
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();
$date->setValue($this->Created);
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".