Welcome Guest, Not a member yet? Register   Sign In
having problem printing out "created_at" date
#11

(This post was last modified: 09-06-2021, 11:37 AM by ikesela.)

(09-06-2021, 06:58 AM)chakycool Wrote: Tried this and I get a error " Call to a member function getTime() on null"

SYSTEMPATH\I18n\Time.php at line 1168

      *
1162      * @return mixed
1163      * @throws Exception
1164      */
1165    public function humanize()
1166    {
1167        $now  = IntlCalendar::fromDateTime(Time::now($this->timezone)->toDateTimeString());
1168        $time = $this->getCalendar()->getTime();

Other alternative for humanize:

Code:
echo $item->created_at; // this should work out , print_r will print it property
        $new = Codeigniter\I18n\Time::parse($item->created_at);
        echo $new->humanize();
Reply
#12

Thanks ikesela for the suggestion but I still get the same error as before.

"Call to a member function getTime() on null"

"created_at" is not just a string when is comes out via Ci4.
Reply
#13

You can use the TimeDifference class
PHP Code:
$time $item->created_at// instance of Time
$difference $time->difference('9 September 2021''UTC'); // will give you a TimeDifference instance between your created_at date and 9 September
echo $difference->humanize(); 
Reply
#14

Hi Paul, thanks for the suggestion but I found the issue.

Everybody who specify the "public $appTimezone" make sure it's in camel case. I had it all in lower case and all worked but the Humanization.

Example :
public $appTimezone = 'America/Chicago';
Reply
#15

you should post your entity class here. something not right with your code maybe. since i test on my entity class for created_at, it work perfectly.
Reply
#16

(09-12-2021, 10:39 AM)ikesela Wrote: you should post your entity class here. something not right with your code maybe. since i test on my entity class for created_at, it work perfectly.

Thank you, but I just got the "$appTimezone" wrong. All good now.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB