Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » date.ago wrong calculation?

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

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

Page: 1
Go to End
Author Topic: 764 Views
  • lx
    Avatar
    Community Member
    82 Posts

    date.ago wrong calculation? Link to this post

    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

  • lx
    Avatar
    Community Member
    82 Posts

    Re: date.ago wrong calculation? Link to this post

    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".

    764 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.