# Chronos FormattingTrait

**URL:** <https://discourse.cakephp.org/t/chronos-formattingtrait/1239>\
**Category:** Uncategorized\
**Created:** [September 24, 2016, 5:35pm UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239 "2016-09-24T17:35:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [September 24, 2016, 5:35pm UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239/1 "2016-09-24T17:35:29Z")

</div>

I dug around in the code and found FormattingTrait, it has a method

```auto
public function toDateTimeString()
    {
        return $this->format('Y-m-d H:i:s');
    }

```

But in a view, how do you call this method? I am still trying to figure out date time in cakephp.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [September 24, 2016, 6:06pm UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239/2 "2016-09-24T18:06:42Z")

</div>

Well found this in the docs

```auto

Formatting Strings

Chronos provides a number of methods for displaying our outputting datetime objects:

// Uses the format controlled by setToStringFormat()
echo $date;

// Different standard formats
echo $time->toAtomString(); // 1975-12-25T14:15:16-05:00
echo $time->toCookieString(); // Thursday, 25-Dec-1975 14:15:16 EST
echo $time->toIso8601String(); // 1975-12-25T14:15:16-05:00
echo $time->toRfc822String(); // Thu, 25 Dec 75 14:15:16 -0500
echo $time->toRfc850String(); // Thursday, 25-Dec-75 14:15:16 EST
echo $time->toRfc1036String(); // Thu, 25 Dec 75 14:15:16 -0500
echo $time->toRfc1123String(); // Thu, 25 Dec 1975 14:15:16 -0500
echo $time->toRfc2822String(); // Thu, 25 Dec 1975 14:15:16 -0500
echo $time->toRfc3339String(); // 1975-12-25T14:15:16-05:00
echo $time->toRssString(); // Thu, 25 Dec 1975 14:15:16 -0500
echo $time->toW3cString(); // 1975-12-25T14:15:16-05:00

// Get the quarter
echo $time->toQuarter(); // 4;

```

Apparently a genius decided to leave out this example:

```auto
toDateTimeString()

```

If toDateTimeString() is in the docs anywhere it is well hidden, those docs leave much to be desired.  
Also I notice no “use” statement is needed, this seems to work fine:

```auto
echo "<td style=\"width:40px;\">" . $row->lastedit->toDateTimeString() . "</td>";

```

The docs could stand to have better examples for folks new to cakephp. If I had not come from laravel which uses traits, I would have never figured this out. How is a newcomer? Also what is that I18n stuff, I got it formatted with no I18n. So this is also very confusing, the I18n topic.

Wouldn’t cakephp be better off just using php built in date time stuff?

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [September 24, 2016, 6:50pm UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239/3 "2016-09-24T18:50:26Z")

</div>

I created an issue since a method was left out of the docs. To me Y-m-d H:i:s is a standard as well since a major database, mysql stores datetime in that format. The issue is #4340

---

<div class="post-metadata">

**Author:** ![markstory](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/markstory/32/182_2.png) [@markstory](https://discourse.cakephp.org/u/markstory)\
**Post date:** [September 28, 2016, 3:01am UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239/4 "2016-09-28T03:01:52Z")

</div>

> [@jimgwhit](#):
>
> Apparently a genius decided to leave out this example:

That genius would be me. I also happen to be the genius who updated the docs 😄 I didn’t originally include all the methods as I didn’t forsee people using them all. I was wrong.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [September 28, 2016, 4:30pm UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239/5 "2016-09-28T16:30:29Z")

</div>

@markstory thanks, and the genius thing was just a Cliche. Funny, Laravel just natively works with the mysql formatted date out of the box. I wish cake did also. My rule of thumb is just to use the date format native to the database. If sqlserver I’d do it different.

---

<div class="post-metadata">

**Author:** ![deanoj](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@deanoj](https://discourse.cakephp.org/u/deanoj)\
**Post date:** [April 13, 2017, 2:13pm UTC](https://discourse.cakephp.org/t/chronos-formattingtrait/1239/6 "2017-04-13T14:13:31Z")

</div>

> Wouldn’t cakephp be better off just using php built in date time stuff?

If you want to write unit tests that depend on Date or Time, the fixation feature of Chronos is brilliant - and the reason I used Chronos everywhere in my cake application.

[https://book.cakephp.org/3.0/en/chronos.html#testing-aids](https://book.cakephp.org/3.0/en/chronos.html#testing-aids)
